/*
 ***************************************************************************
 * MediaTeK Inc.
 * 4F, No. 2 Technology	5th	Rd.
 * Science-based Industrial	Park
 * Hsin-chu, Taiwan, R.O.C.
 *
 * (c) Copyright 2002-2012, MTK.
 *
 * All rights reserved.	MediaTeK's source	code is	an unpublished work	and	the
 * use of a	copyright notice does not imply	otherwise. This	source code
 * contains	confidential trade secret material of MediaTeK Tech. Any attemp
 * or participation	in deciphering,	decoding, reverse engineering or in	any
 * way altering	the	source code	is stricitly prohibited, unless	the	prior
 * written consent of MediaTeK, Inc. is obtained.
 ***************************************************************************

	Module Name:
	omci_me_mac_bridge_func.c

	Abstract:

	Revision History:
	Who			When			What
	--------	----------		----------------------------------------------
	Name		Date			Modification logs
	wayne.lee	2012/7/28	Create
*/

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include "libcompileoption.h"
#include "omci_adpt_general.h"
#include "lib_bbf247.h"

//#ifndef BSP_BUILD
#include "blapi_traffic.h"
//#endif

/* global variable */
uint16_t validAniPortFlag[MAX_OMCI_ANI_PORT_NUM][MAX_OMCI_ANI_PORT_VALID_NUM] = {{0,OMCI_INVALID_MAC_BRIDGE_PORT_FLAG}};//9.3.4 instance id , valid or invalid ANI interface
mb_port_info_ptr gMBPortInfo_ptr = NULL;
extern pthread_mutex_t omciHandlePonIfc;
extern pthread_mutex_t omciSetMBPDevId;
extern pthread_mutex_t omciGetAllData;

mb_uni_ani_port_t ani_uni_port[MAX_GEM_PORT_NUM];
mb_all_gemport_t ani_gemport[MAX_GEM_PORT_NUM];



int setMBSPLearningIndValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int getMBSPPortBridingIndValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMBSPPortBridingIndValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int getMBSPUnKnownMacAddrDiscardValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMBSPUnKnownMacAddrDiscardValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMBSPMacAddrLimitValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);

int setMBPMHDThresholdDataIdValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);

int getMBCDBridgeMACAddrValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int getMBCDBridgePriorityValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int getMBCDDesignatedRootValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int getMBCDRootPathCostValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int getMBCDBridgePortCountValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int getMBCDRootPortNumValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);

int setMBPCDTPTypeValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMBPCDTPPointerValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int getMBPCDportMacAddressValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMBPCDoutTDPointerValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMBPCDinTDPointerValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMBPCDMacAddrLimitValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int omci_mac_br_port_cfg_data_delete_op(management_entry_ptr me_entry, omci_me_info_ptr me_info);

int getMBPDDPortStateValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);

int getMBPFTmacFilterTableValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMBPFTmacFilterTableValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int omci_mac_br_port_filter_delete_op(management_entry_ptr me_entry, omci_me_info_ptr me_info);

int setMBPFPTipv4MulticastFilterValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMBPFPTipv6MulticastFilterValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMBPFPTipv4BroadcastFilterValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMBPFPTRARPFilterValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMBPFPTIPXFilterValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMBPFPTNetBEULFilterValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMBPFPTappleTalkFilterValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMBPFPTmanageInfoFilterValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMBPFPTARPFilterValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMBPFPTPPPoEBroadcastFilterValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int omci_mac_br_port_filter_pre_delete_op(management_entry_ptr me_entry, omci_me_info_ptr me_info);

int getBPBTDBridgeTableValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);


/*******************************************************************************************************************************
9.3.1 MAC Bridge Service Profile ME

********************************************************************************************************************************/
attribute_func_t mbspSpanningTreeIndFunc = {
	NULL,
	NULL
};

attribute_func_t mbspLlearningIndFunc = {
	NULL,
	setMBSPLearningIndValue
};

attribute_func_t mbspPortBridingIndFunc = {
	getMBSPPortBridingIndValue,
	setMBSPPortBridingIndValue
};

attribute_func_t mbspPriorityFunc = {
	NULL,
	NULL
};

attribute_func_t mbspMaxAgeFunc = {
	NULL,
	NULL
};

attribute_func_t mbspHelloTimeFunc = {
	NULL,
	NULL
};

attribute_func_t mbspForwardDelayFunc = {
	NULL,
	NULL
};

attribute_func_t mbspUnKnownMacAddrDiscardFunc = {
	getMBSPUnKnownMacAddrDiscardValue,
	setMBSPUnKnownMacAddrDiscardValue
};

attribute_func_t mbspMacAddrLimitFunc = {
	NULL,
	setMBSPMacAddrLimitValue 
};

omci_attr_dscp_t omci_attr_mac_br_service_op[]={
	{0, "Managed entity id" ,           2, ATTR_ACCESS_R_SET_CREATE ,       ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},	
	{1, "Spanning tree ind" ,           1, ATTR_ACCESS_R_W_SET_CREATE ,     ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{2, "Learning ind" ,                1, ATTR_ACCESS_R_W_SET_CREATE ,     ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &mbspLlearningIndFunc},	
	{3, "Port bridging ind" ,           1, ATTR_ACCESS_R_W_SET_CREATE ,     ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &mbspPortBridingIndFunc},	
	{4, "Priority" ,                    2, ATTR_ACCESS_R_W_SET_CREATE ,     ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{5, "Max age" ,                     2, ATTR_ACCESS_R_W_SET_CREATE ,     ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{6, "Hello time" ,                  2, ATTR_ACCESS_R_W_SET_CREATE ,     ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{7, "Forward delay" ,               2, ATTR_ACCESS_R_W_SET_CREATE ,     ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{8, "Unknown MAC addr discard" ,    1, ATTR_ACCESS_R_W_SET_CREATE ,     ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},	/*it is always 0*/
	{9, "MAC learning depth" ,          1, ATTR_ACCESS_R_W_SET_CREATE ,     ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &mbspMacAddrLimitFunc},
	{10, "Dynamic filter age time",     4, ATTR_ACCESS_R_W_SET_CREATE ,     ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{255, 	"", 					    0 , 0,                          0,                           0,                     NULL}
};
omci_me_func_t omci_me_mac_br_service_op ={
	omci_me_general_create_op,
	omci_me_general_delete_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
};

omci_mac_br_service_t omci_mac_br_service_attr_data = {0};

omci_attr_t omci_mac_br_service_attr ={
	(uint8_t *)&omci_mac_br_service_attr_data,
	sizeof(omci_mac_br_service_attr_data),
};


/*******************************************************************************************************************************
9.3.2 MAC Bridge Configuration Data ME

********************************************************************************************************************************/
attribute_func_t mbcdBridgeMACAddrFunc = {
	getMBCDBridgeMACAddrValue,
	NULL
};
attribute_func_t mbcdBridgePriorityFunc = {
	getMBCDBridgePriorityValue,
	NULL
};
attribute_func_t mbcdDesignatedRootFunc = {
	getMBCDDesignatedRootValue,
	NULL
};	
attribute_func_t mbcdRootPathCostFunc = {
	getMBCDRootPathCostValue,
	NULL
};
attribute_func_t mbcdBridgePortCountFunc = {
	getMBCDBridgePortCountValue,
	NULL
};

attribute_func_t mbcdRootPortNumFunc = {
	getMBCDRootPortNumValue,
	NULL
};

omci_attr_dscp_t omci_attr_mac_br_cfg_data_op[]={
	{0, "Managed entity id" ,           2 , ATTR_ACCESS_R ,     ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{1, "Bridge MAC address" ,          6 , ATTR_ACCESS_R ,     ATTR_FORMAT_STRING,  	   ATTR_FULLY_SUPPORT,	&mbcdBridgeMACAddrFunc},
	{2, "Bridge priority" ,             2 , ATTR_ACCESS_R ,     ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,	&mbcdBridgePriorityFunc},
	{3, "Designated root" ,         	8 , ATTR_ACCESS_R ,     ATTR_FORMAT_STRING,   	   ATTR_FULLY_SUPPORT,	&mbcdDesignatedRootFunc},
	{4, "Root path cost" ,              4 , ATTR_ACCESS_R ,     ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,	&mbcdRootPathCostFunc},
	{5, "Bridge port count" ,           1 , ATTR_ACCESS_R ,     ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,	&mbcdBridgePortCountFunc},
	{6, "Root port num" ,               2 , ATTR_ACCESS_R ,     ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,	&mbcdRootPortNumFunc}, 
	{7, "Hello time" ,                  2 , ATTR_ACCESS_R ,     ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{8, "Forward delay" ,               2 , ATTR_ACCESS_R ,     ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{255, 	"", 					    0 , 0,                          0,                           0,                     NULL}
};
omci_me_func_t omci_me_mac_br_cfg_data_op ={
	omci_me_general_create_op,
	omci_me_general_delete_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
};

omci_mac_br_cfg_data_t omci_mac_br_cfg_data_attr_data = {0};

omci_attr_t omci_mac_br_cfg_data_attr ={
	(uint8_t *)&omci_mac_br_cfg_data_attr_data,
	sizeof(omci_mac_br_cfg_data_attr_data),
};


/*******************************************************************************************************************************
9.3.3 MAC bridge performance monitoring history data ME

********************************************************************************************************************************/

omci_attr_dscp_t omci_attr_mac_br_pm_his_op[]={
	{0, "Managed entity id" ,           2 , ATTR_ACCESS_R_SET_CREATE ,      ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT, 	&generalAttrFunc},
	{1, "Interval end time" ,           1 , ATTR_ACCESS_R ,                 ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT, 	&generalAttrFunc},
	{2, "Threshold data 1/2 id" ,       2 , ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_POINTER,      ATTR_FULLY_SUPPORT, 	&generalAttrFunc},
	{3, "entry discard count" ,         4 , ATTR_ACCESS_R ,                 ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT, 	&generalAttrFunc},
	{255, 	"", 					    0 , 0,                              0,                           0,                     NULL}
};

omci_me_func_t omci_me_mac_br_pm_his_op ={
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_set_op,
	omci_me_general_pm_history_get_op,
	omci_me_mac_bridge_pm_history_get_curr_op
};

omci_mac_br_pm_his_t omci_mac_br_pm_his_attr_data = {0};

omci_attr_t omci_mac_br_pm_his_attr ={
	(uint8_t *)&omci_mac_br_pm_his_attr_data,
	sizeof(omci_mac_br_pm_his_attr_data),
};

int get_mac_bridge_pm_history_data(pm_history_data_list_ptr pm_list, uint8_t syncFlag)
{
    //driver do not implement, history data always 0, and do not save the current data.

    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
    
    if(syncFlag)
    {
        pm_list->pm_data.mac_br_pm.interEndTime = pmIntervalTimes;
    	pm_list->pm_data.mac_br_pm.brLearnEntryDisCnt = 0; 
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG, "[%s][%d]15min->brLearnEntryDisCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.mac_br_pm.brLearnEntryDisCnt);
    }
        
    return 0;
}

int omci_me_mac_bridge_pm_history_get_curr_op(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
    omci_mac_br_pm_his_ptr mac_br_pm_new = NULL;
  
    if(me_entry == NULL || me_info == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]pointer is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    mac_br_pm_new = (omci_mac_br_pm_his_ptr)me_info->attributes;
    if(mac_br_pm_new == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]me info attribute is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }

	mac_br_pm_new->interEndTime = pmIntervalTimes;
	mac_br_pm_new->brLearnEntryDisCnt = 0;
	
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG, "[%s][%d]->brLearnEntryDisCnt = 0x%x\n",__FUNCTION__,__LINE__, mac_br_pm_new->brLearnEntryDisCnt);

    return 0;
}

int omci_me_mac_bridge_pm_history_notify(pm_history_data_list_ptr pm_list, omci_me_info_t threshold_info)
{
    enum{ MAC_BRIDGE_PM_HISTORY_DATA_TCA_NUM = 1};
    omci_threshold_data_1_ptr threshold_data1 = NULL;
    int i = 0;
    uint32_t currentData[MAC_BRIDGE_PM_HISTORY_DATA_TCA_NUM] = {0};
    static uint8_t reportFlag[MAC_BRIDGE_PM_HISTORY_DATA_TCA_NUM] = {0};
    uint8_t alarm_num[MAC_BRIDGE_PM_HISTORY_DATA_TCA_NUM] = {0};    
    tca_notify_info_t tca_info = {0};

    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(omci_pm_is_end_of_interval_time())
    {
        memset(reportFlag, 0, sizeof(reportFlag));
        return 0;
    }
    if(threshold_info.class_id != OMCI_CLASS_ID_THRESHOLD_DATA1){
        return 0;
    }


	threshold_data1 =  (omci_threshold_data_1_ptr)threshold_info.attributes; 
	if(threshold_data1 == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  threshold value is NULL \n",__FUNCTION__,__LINE__);
        return -1;
    }

	//driver do not implement, so the current data is always 0.

    for(i = 0; i < MAC_BRIDGE_PM_HISTORY_DATA_TCA_NUM; i++)
    {
        tca_info.classId = pm_list->classId;
        tca_info.instId = pm_list->instId;
        tca_info.currentData = currentData[i];
        tca_info.threshold = threshold_data1->thresholdValue[i];
        tca_info.alarm_num = alarm_num[i];
        tca_info.reportFlag = reportFlag[i];

        reportFlag[i] = omci_pm_report_alarm_by_tca_info(tca_info, 0);
	}

	return 0;
    
}

/*******************************************************************************************************************************
9.3.4 MAC bridge port configuration data

********************************************************************************************************************************/
attribute_func_t mbPortCfgDataTPTypeFunc = {
	NULL,
	setMBPCDTPTypeValue
};

attribute_func_t mbPortCfgDataTPPointerFunc = {
	NULL,
	setMBPCDTPPointerValue
};
 
attribute_func_t mbPortCfgDataPortMacAddressFunc = {
	getMBPCDportMacAddressValue,
	NULL
};

attribute_func_t mbPortCfgDataOutTDPointerFunc = {
	NULL,
	setMBPCDoutTDPointerValue
};
attribute_func_t mbPortCfgDataInTDPointerFunc = {
	NULL,
	setMBPCDinTDPointerValue
};
attribute_func_t mbPortCfgDataMacAddrLimitFunc = {
	 NULL,
	 setMBPCDMacAddrLimitValue
};

omci_attr_dscp_t omci_attr_mac_br_port_cfg_op[]={
	{0, "Managed entity id" ,           2 , ATTR_ACCESS_R_SET_CREATE,       ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  	&generalAttrFunc},	
	{1, "Bridge id pointer" ,           2 , ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_POINTER,      ATTR_FULLY_SUPPORT,  	&generalAttrFunc},	
	{2, "Port num" ,                    1 , ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  	&generalAttrFunc},	
	{3, "TP type" ,                     1 , ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  	&mbPortCfgDataTPTypeFunc},
	{4, "TP pointer" ,                  2 , ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_POINTER,      ATTR_FULLY_SUPPORT,  	&mbPortCfgDataTPPointerFunc},	
	{5, "Port priority" ,               2 , ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  	&generalAttrFunc},	
	{6, "Port path cost" ,              2 , ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT, 	&generalAttrFunc},	
	{7, "Port ST ind" ,                 1 , ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  	&generalAttrFunc},	
	{8, "Deprecated 1" ,                1 , ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  	&generalAttrFunc},	
	{9, "Deprecated 2" ,                1 , ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  	&generalAttrFunc},	
	{10, "Port MAC Address" ,           6 , ATTR_ACCESS_R,                  ATTR_FORMAT_STRING,   	  ATTR_FULLY_SUPPORT,  	&mbPortCfgDataPortMacAddressFunc},	
	{11, "Outbound TD pointer" ,        2 , ATTR_ACCESS_R_W,                ATTR_FORMAT_POINTER,      ATTR_FULLY_SUPPORT,  	&mbPortCfgDataOutTDPointerFunc},	
	{12, "Inbound TD pointer" ,         2 , ATTR_ACCESS_R_W,                ATTR_FORMAT_POINTER,      ATTR_FULLY_SUPPORT,  	&mbPortCfgDataInTDPointerFunc},	
	{13, "MAC learning depth" ,         1 , ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  	&mbPortCfgDataMacAddrLimitFunc},	
	{255, 	"", 					    0 , 0,                              0,                           0,                     NULL}
};

omci_me_func_t omci_me_mac_br_port_cfg_op ={
	omci_me_general_create_op,
	omci_mac_br_port_cfg_data_delete_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
};

omci_mac_br_port_cfg_t omci_mac_br_port_cfg_attr_data = {0};

omci_attr_t omci_mac_br_port_cfg_attr ={
	(uint8_t *)&omci_mac_br_port_cfg_attr_data,
	sizeof(omci_mac_br_port_cfg_attr_data),
};

/*******************************************************************************************************************************
9.3.5 MAC bridge port designation data

********************************************************************************************************************************/

attribute_func_t mbPortDesDataPortStateFunc = {
	getMBPDDPortStateValue,
	NULL
};

omci_attr_dscp_t omci_attr_mac_br_port_dest_op[]={
	{0, "Managed entity id" ,           2,  ATTR_ACCESS_R,  ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,&generalAttrFunc},
	 /* include port identifier, root identifier, designated port number, port path cost*/
	{1, "bridge root cost port" ,       24, ATTR_ACCESS_R,  ATTR_FORMAT_STRING,   	  ATTR_FULLY_SUPPORT,&generalAttrFunc},
	{2, "Port state" ,                  1,  ATTR_ACCESS_R,  ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,&mbPortDesDataPortStateFunc},
	{255, 	"", 					    0 , 0,                          0,                           0,                     NULL}
};

omci_me_func_t omci_me_mac_br_port_dest_op ={
	omci_me_general_create_op,
	omci_me_general_delete_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
};

omci_mac_br_port_dest_t omci_mac_br_port_dest_attr_data = {0};

omci_attr_t omci_mac_br_port_dest_attr ={
	(uint8_t *)&omci_mac_br_port_dest_attr_data,
	sizeof(omci_mac_br_port_dest_attr_data),
};

/*******************************************************************************************************************************
9.3.6 mac bridge port filter table 

********************************************************************************************************************************/
attribute_func_t mbPortFilterTableFunc = {
	getMBPFTmacFilterTableValue,
	setMBPFTmacFilterTableValue
};
omci_attr_dscp_t omci_attr_mac_br_port_filter_op[]={
	{0, "Managed entity id",    2,  ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  	&generalAttrFunc},
	{1, "Mac filter table",     8,  ATTR_ACCESS_R_W,    ATTR_FORMAT_TABLE,         ATTR_FULLY_SUPPORT, 	&mbPortFilterTableFunc},
	{255, 	"", 				0 , 0,                          0,                           0,                     NULL}
};

omci_me_func_t omci_me_mac_br_port_filter_op ={
	omci_me_general_create_op,
	omci_mac_br_port_filter_delete_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
};

omci_mac_br_port_filter_t omci_mac_br_port_filter_attr_data = {0};

omci_attr_t omci_mac_br_port_filter_attr ={
	(uint8_t *)&omci_mac_br_port_filter_attr_data,
	sizeof(omci_mac_br_port_filter_attr_data),
};

/*******************************************************************************************************************************
9.3.7 mac bridge port filter preassign table

********************************************************************************************************************************/
attribute_func_t mbpPreFilterIpv4MulticastFilterFunc = {
	NULL,
	setMBPFPTipv4MulticastFilterValue
};
attribute_func_t mbpPreFilterIpv6MulticastFilterFunc = {
	NULL,
	setMBPFPTipv6MulticastFilterValue
};
attribute_func_t mbpPreFilterIpv4BroadcastFilterFunc = {
	NULL,
	setMBPFPTipv4BroadcastFilterValue
};
attribute_func_t mbpPreFilterRARPFilterFunc = {
	NULL,
	setMBPFPTRARPFilterValue
};
attribute_func_t mbpPreFilterIPXFilterFunc = {
	NULL,
	setMBPFPTIPXFilterValue
};
attribute_func_t mbpPreFilterNetBEULFilterFunc = {
	NULL,
	setMBPFPTNetBEULFilterValue
};

attribute_func_t mbpPreFilterappleTalkFilterFunc = {
	NULL,
	setMBPFPTappleTalkFilterValue
};
attribute_func_t mbpPreFilterManageInfoFilterFunc = {
	NULL,
	setMBPFPTmanageInfoFilterValue
};
attribute_func_t mbpPreFilterARPFilterFunc = {
	NULL,
	setMBPFPTARPFilterValue
};
attribute_func_t mbpPreFilterPPPoEBroadcastFilterFunc = {
	NULL,
	setMBPFPTPPPoEBroadcastFilterValue
};

omci_attr_dscp_t omci_attr_mac_br_port_filter_pre_op[]={
	{0, "Managed entity id",            2,  ATTR_ACCESS_R,      ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,	 &generalAttrFunc},
	{1, "ipv4 multicast filter",        1,  ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,	 &mbpPreFilterIpv4MulticastFilterFunc},
	{2, "ipv6 multicast filter",        1,  ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,	 &mbpPreFilterIpv6MulticastFilterFunc},
	{3, "ipv4 broadcast filter",        1,  ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,	 &mbpPreFilterIpv4BroadcastFilterFunc},
	{4, "RARP filter",                  1,  ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,	 &mbpPreFilterRARPFilterFunc},
	{5, "IPX filter",                   1,  ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,	 &mbpPreFilterIPXFilterFunc},
	{6, "NetBEUI filter",               1,  ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,	 &mbpPreFilterNetBEULFilterFunc},
	{7, "AppleTalk filter",             1,  ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,	 &mbpPreFilterappleTalkFilterFunc},
	{8, "Bridge manage info  filter",   1,  ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,	 &mbpPreFilterManageInfoFilterFunc},
	{9, "ARP filter",                   1,  ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,	 &mbpPreFilterARPFilterFunc},
	{10,"PPPoE broadcast filter",   	1,  ATTR_ACCESS_R_W,    ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,	 &mbpPreFilterPPPoEBroadcastFilterFunc},
	{255, 	"", 					    0 , 0,                          0,                           0,                     NULL}
};

omci_me_func_t omci_me_mac_br_port_filter_pre_op ={
	omci_me_general_create_op,
	omci_mac_br_port_filter_pre_delete_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
};

omci_mac_br_port_filter_pre_t omci_mac_br_port_filter_pre_attr_data = {0};

omci_attr_t omci_mac_br_port_filter_pre_attr ={
	(uint8_t *)&omci_mac_br_port_filter_pre_attr_data,
	sizeof(omci_mac_br_port_filter_pre_attr_data),
};

/*******************************************************************************************************************************
9.3.8 mac bridge port bridge table data

********************************************************************************************************************************/
attribute_func_t mbPortBridgeTableFunc = {
	getBPBTDBridgeTableValue,
	NULL
};
omci_attr_dscp_t omci_attr_mac_br_port_br_tbl_op[]={
	{0, "Managed entity id",    2,  ATTR_ACCESS_R,  ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT, 	&generalAttrFunc},
	{1, "Bridge table",         8,  ATTR_ACCESS_R,  ATTR_FORMAT_TABLE,         ATTR_FULLY_SUPPORT, &mbPortBridgeTableFunc},
	{255, 	"", 				0, 	0, 	0, 	0, 	NULL}
};
omci_me_func_t omci_me_mac_br_port_br_tbl_op ={
	omci_me_general_create_op,
	omci_me_general_delete_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
};

omci_mac_br_port_br_tbl_t omci_mac_br_port_br_tbl_attr_data = {0};

omci_attr_t omci_mac_br_port_br_tbl_attr ={
	(uint8_t *)&omci_mac_br_port_br_tbl_attr_data,
	sizeof(omci_mac_br_port_br_tbl_attr_data),
};

/*******************************************************************************************************************************
9.3.9 mac bridge port performance monitoring history data

********************************************************************************************************************************/

omci_attr_dscp_t omci_attr_mac_br_port_pm_his_op[]={
	{0, "Managed entity id" ,           2 , ATTR_ACCESS_R_SET_CREATE ,  ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{1, "Interval end time" ,           1 , ATTR_ACCESS_R ,             ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{2, "Threshold data 1/2 id" ,       2 , ATTR_ACCESS_R_W_SET_CREATE, ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{3, "Forwarded frame cnt" ,         4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{4, "Delay exceeded discard cnt" ,  4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{5, "MTU exceeded discard cnt" ,    4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{6, "Received frame cnt" ,          4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{7, "Received and discarded cnt" ,  4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{255, 	"", 					    0 , 0,                          0,                           0,                     NULL}
};

int get_mac_br_port_data(MACBridgePortPmCounters_t *data, uint16_t portId)
{
	uint32_t ifcType = 0;
	uint32_t tempPortId = 0;
	uint32_t cnt = 0;
	int i = 0, j = 0;

	if(data == NULL){
		return -1;
	}	
	
	for(i = 0; i < MAX_GEM_PORT_NUM; i++){
		if(ani_uni_port[i].valid && ani_uni_port[i].index == portId){
			ifcType = ani_uni_port[i].ifaceType;
			break;
		}
	}
	if(i == MAX_GEM_PORT_NUM){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]can not find ifcType\n", __FUNCTION__, __LINE__);
		return -1;
	}
			
	if((ifcType != PM_LAN_INTERFACE_0) && (ifcType != PM_WAN_INTERFACE_1) ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]->ifcType =%d fail\n", __FUNCTION__, __LINE__, ifcType);
		return -1;
	}
	
	/*get all port and caculate PM counter*/
	if(ifcType == PM_LAN_INTERFACE_0){//LAN port
		tempPortId = ani_uni_port[i].lan_portId-1;
		if(macMT7530GetPortTxSuccFramesCnt(tempPortId, &cnt) == 0){
			data->forwardFrameCnts += cnt;
		}
		
		data->delayExceededDiscardCnts = 0;
		data->mtuExceededDiscardCnts = 0;
		
		if(macMT7530GetPortRxPktsCnt(tempPortId, &cnt) == 0){
			data->receivedFrameCnts += cnt;
		}
		if(macMT7530GetPortRxDropFramesCnt(tempPortId, &cnt) == 0){
			data->receivedDiscardCnts += cnt;
		}
	}else if(ifcType == PM_WAN_INTERFACE_1){//gem port
		for(j = 0; j< ani_uni_port[i].gemNum; j++){
			tempPortId = ani_uni_port[i].gemPortList[j];
		}
#if 0
		if(PonApi_PonTestCmd_Get(&getEntry) == EXEC_OK){
			pm->forwardFrameCnts += getEntry.value1;
			pm->delayExceededDiscardCnts += getEntry.value1;
			pm->mtuExceededDiscardCnts += getEntry.value1;
			pm->receivedFrameCnts += getEntry.value1;
			pm->receivedDiscardCnts += getEntry.value1;
		}
#endif

	}else{
		//nothing
	}

	return 0;
}


int get_mac_br_port_pm_history_data(pm_history_data_list_ptr pm_list, uint8_t syncFlag)
{
    MACBridgePortPmCounters_t mac_br_port = {0};

    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(get_mac_br_port_data(&mac_br_port, pm_list->instId) != 0)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]->get_mac_br_port_data fail.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(syncFlag)
    {
        pm_list->pm_data.mac_br_port_pm.interEndTime = pmIntervalTimes;
    	pm_list->pm_data.mac_br_port_pm.forwardFrameCnt= mac_br_port.forwardFrameCnts - pm_list->pm_prev_data.macBriPort.forwardFrameCnts;
    	pm_list->pm_data.mac_br_port_pm.delayExceedDisCnt= mac_br_port.delayExceededDiscardCnts - pm_list->pm_prev_data.macBriPort.delayExceededDiscardCnts;
    	pm_list->pm_data.mac_br_port_pm.mtuExceedDisCnt= mac_br_port.mtuExceededDiscardCnts - pm_list->pm_prev_data.macBriPort.mtuExceededDiscardCnts;
        pm_list->pm_data.mac_br_port_pm.receiveFrameCnt= mac_br_port.receivedFrameCnts - pm_list->pm_prev_data.macBriPort.receivedFrameCnts;
        pm_list->pm_data.mac_br_port_pm.receiveDisCnt= mac_br_port.receivedDiscardCnts - pm_list->pm_prev_data.macBriPort.receivedDiscardCnts;

        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->forwardFrameCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.mac_br_port_pm.forwardFrameCnt);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->delayExceedDisCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.mac_br_port_pm.delayExceedDisCnt);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->mtuExceedDisCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.mac_br_port_pm.mtuExceedDisCnt);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->receiveFrameCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.mac_br_port_pm.receiveFrameCnt);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->receiveDisCnt = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_data.mac_br_port_pm.receiveDisCnt);        
    }

    memcpy(&pm_list->pm_prev_data.macBriPort, &mac_br_port, sizeof(MACBridgePortPmCounters_t));

    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->forwardFrameCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.macBriPort.forwardFrameCnts);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->delayExceedDisCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.macBriPort.delayExceededDiscardCnts);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->mtuExceedDisCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.macBriPort.mtuExceededDiscardCnts);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->receiveFrameCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.macBriPort.receivedFrameCnts);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->receiveDisCnt = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_prev_data.macBriPort.receivedDiscardCnts);
	
    return 0;
}

int omci_me_mac_br_port_pm_history_get_curr_op(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
    omci_mac_br_port_pm_his_ptr mac_br_port_pm_new = NULL;
    MACBridgePortPmCounters_t mac_br_port = {0};

    if(me_entry == NULL || me_info == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]pointer is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    mac_br_port_pm_new = (omci_mac_br_port_pm_his_ptr)me_info->attributes;
    if(mac_br_port_pm_new == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]me info attribute is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(get_mac_br_port_data(&mac_br_port, me_info->inst_id) != 0)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]->get_mac_br_port_data fail.\n",__FUNCTION__,__LINE__);
        return -1;
    }

	mac_br_port_pm_new->interEndTime = pmIntervalTimes;
	mac_br_port_pm_new->forwardFrameCnt = mac_br_port.forwardFrameCnts;
	mac_br_port_pm_new->delayExceedDisCnt = mac_br_port.delayExceededDiscardCnts;
	mac_br_port_pm_new->mtuExceedDisCnt = mac_br_port.mtuExceededDiscardCnts;
	mac_br_port_pm_new->receiveFrameCnt = mac_br_port.receivedFrameCnts;
	mac_br_port_pm_new->receiveDisCnt = mac_br_port.receivedDiscardCnts;
	

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d]->forwardFrameCnt = 0x%x\n",__FUNCTION__,__LINE__, mac_br_port_pm_new->forwardFrameCnt);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d]->delayExceedDisCnt = 0x%x\n",__FUNCTION__,__LINE__, mac_br_port_pm_new->delayExceedDisCnt);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d]->mtuExceedDisCnt = 0x%x\n",__FUNCTION__,__LINE__, mac_br_port_pm_new->mtuExceedDisCnt);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d]->receiveFrameCnt = 0x%x\n",__FUNCTION__,__LINE__, mac_br_port_pm_new->receiveFrameCnt);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d]->receiveDisCnt = 0x%x\n",__FUNCTION__,__LINE__,mac_br_port_pm_new->receiveDisCnt);

    return 0;
}


int omci_me_mac_br_port_pm_history_notify(pm_history_data_list_ptr pm_list, omci_me_info_t threshold_info)
{
    enum{ MAC_BR_PORT_PM_HISTORY_DATA_TCA_NUM = 3};
    omci_threshold_data_1_ptr threshold_data1 = NULL;
    int i = 0;
    uint32_t currentData[MAC_BR_PORT_PM_HISTORY_DATA_TCA_NUM] = {0};
    static uint8_t reportFlag[MAC_BR_PORT_PM_HISTORY_DATA_TCA_NUM] = {0};
    uint8_t alarm_num[MAC_BR_PORT_PM_HISTORY_DATA_TCA_NUM] = {1, 2, 4};
    tca_notify_info_t tca_info = {0};
    MACBridgePortPmCounters_t mac_br_port = {0};

    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(omci_pm_is_end_of_interval_time())
    {
        memset(reportFlag, 0, sizeof(reportFlag));
        return 0;
    }
    if(threshold_info.class_id != OMCI_CLASS_ID_THRESHOLD_DATA1){
        return 0;
    }

	threshold_data1 =  (omci_threshold_data_1_ptr)threshold_info.attributes;
	if(threshold_data1 == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  threshold value is NULL \n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(get_mac_br_port_data(&mac_br_port, pm_list->instId) != 0)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]->get_mac_br_port_data fail.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    /*monitor 15min interval tca attribute value*/
	currentData[0]= mac_br_port.delayExceededDiscardCnts - pm_list->pm_prev_data.macBriPort.delayExceededDiscardCnts;
	currentData[1] = mac_br_port.mtuExceededDiscardCnts - pm_list->pm_prev_data.macBriPort.mtuExceededDiscardCnts;
	currentData[2]= mac_br_port.receivedDiscardCnts - pm_list->pm_prev_data.macBriPort.receivedDiscardCnts;
    

    for(i = 0; i < MAC_BR_PORT_PM_HISTORY_DATA_TCA_NUM; i++)
    {
        tca_info.classId = pm_list->classId;
        tca_info.instId = pm_list->instId;
        tca_info.currentData = currentData[i];
        tca_info.threshold = threshold_data1->thresholdValue[i];
        tca_info.alarm_num = alarm_num[i];
        tca_info.reportFlag = reportFlag[i];

        reportFlag[i] = omci_pm_report_alarm_by_tca_info(tca_info, 0);
	}

	return 0;
    
}


omci_me_func_t omci_me_mac_br_port_pm_his_op ={
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_set_op,
	omci_me_general_pm_history_get_op,
	omci_me_mac_br_port_pm_history_get_curr_op,
};

omci_mac_br_port_pm_his_t omci_mac_br_port_pm_his_attr_data = {0};

omci_attr_t omci_mac_br_port_pm_his_attr ={
	(uint8_t *)&omci_mac_br_port_pm_his_attr_data,
	sizeof(omci_mac_br_port_pm_his_attr_data),
};

/*******************************************************************************************************************************
9.3.30 ethernet frame performance monitoring history data upstream

********************************************************************************************************************************/

omci_attr_dscp_t omci_attr_eth_frame_pm_his_up_op[]={
	{0, "Managed entity id",            2 , ATTR_ACCESS_R_SET_CREATE ,  ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{1, "Interval end time",            1 , ATTR_ACCESS_R ,             ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{2, "Threshold data 1/2 id",        2 , ATTR_ACCESS_R_W_SET_CREATE, ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{3, "Drop events",                  4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{4, "Octets",                       4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{5, "Packets",                      4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{6, "Broadcast packets",            4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{7, "Multicast packets",            4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{8, "CRC errored packets",          4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},	
	{9, "Undersize packets",            4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{10,"Oversize packets",             4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{11,"Packets 64 octets",            4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{12,"Packets 65~127 octets",        4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{13,"Packets 128~255 octets",       4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{14,"Packets 256~511 octets",       4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{15,"Packets 512~1023 octets",      4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{16,"Packets 1024~1518 octets",     4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{255, 	"", 					    0 , 0,                          0,                           0,                     NULL}
};

static int macMT7530GetPortRxOverSizePktsCnt2(uint16_t portid, uint32_t* cnt)
{
	ECNT_SWITCHMGR_PORT_STATISTICS portcnt = {0};

	if(ECNT_SWITCHMGR_SUCCESS == ecnt_switchmgr_lib_get_port_statistics(portid, &portcnt)) {
		*cnt = portcnt.Rx1519_MAXBytePktsCnt;
		return 0;
	}

	return -1;
}

int getMacMT7530PortRXCnt(EthFramePmStreamCounters_t *data, uint16_t PortId)
{
	uint32_t cnt = 0;
	
	if(data == NULL)
	{
	    omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  data is NULL fail\n",__FUNCTION__,__LINE__);
	    return -1;
	}

	if(macMT7530GetPortRxLackDropPktCnt(PortId, &cnt) == 0){
		data->dropEvents = cnt;
	}
	if(macMT7530GetPortRxOctetsCnt(PortId, &cnt) == 0){
		data->octets = cnt;
	}
	if(macMT7530GetPortRxPktsCnt(PortId, &cnt) == 0){
		data->packets = cnt;
	}

	if(macMT7530GetPortRxBroadPktsCnt(PortId, &cnt) == 0){
		data->broadcastPkts = cnt;
	}
	if(macMT7530GetPortRxMultiPktsCnt(PortId, &cnt) == 0){
		data->multicastPkts = cnt;
	}
	if(macMT7530GetPortRxCRCPktsCnt(PortId, &cnt) == 0){
		data->crcErroredPkts = cnt;
	}
	if(macMT7530GetPortRxUnderSizePktsCnt(PortId, &cnt) == 0){
		data->undersizePkts = cnt;
	}

	if(macMT7530GetPortRxOverSizePktsCnt2(PortId, &cnt) == 0)
		data->oversizePkts = cnt;
    
#if 0
	if(macMT7530GetPortRxOverSizePktsCnt(PortId, &cnt) == 0){
		data->oversizePkts = cnt;
	}
#endif

	if(macMT7530GetPortRx64PktsCnt(PortId, &cnt) == 0){
		data->pkts64Octets = cnt;
	}
	if(macMT7530GetPortRx127PktsCnt(PortId, &cnt) == 0){
		data->pkts127Octets = cnt;
	}
	if(macMT7530GetPortRx255PktsCnt(PortId, &cnt) == 0){
		data->pkts255Octets = cnt;
	}
	if(macMT7530GetPortRx511PktsCnt(PortId, &cnt) == 0){
		data->pkts511Octets = cnt;
	}
	if(macMT7530GetPortRx1023PktsCnt(PortId, &cnt) == 0){
		data->pkts1023Octets = cnt;
	}
	if(macMT7530GetPortRx1518PktsCnt(PortId, &cnt) == 0){
		data->pkts1518Octets = cnt;
	}
	return 0;
}

static int macMT7530GetPortTxOverSizePktsCnt2(uint16_t portid, uint32_t* cnt)
{
	ECNT_SWITCHMGR_PORT_STATISTICS portcnt = {0};

	if(ECNT_SWITCHMGR_SUCCESS == ecnt_switchmgr_lib_get_port_statistics(portid, &portcnt)) {
		*cnt = portcnt.Tx1519_MAXBytePktsCnt;
		return 0;
	}

	return -1;
}

int getMacMT7530PortTXCnt(EthFramePmStreamCounters_t *data, uint16_t PortId)
{
	uint32_t cnt = 0;

	if(data == NULL)
	{
	    omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  data is NULL fail\n",__FUNCTION__,__LINE__);
	    return -1;
	}
	data->dropEvents = 0;
	if(macMT7530GetPortTxOctetsCnt(PortId, &cnt) == 0){
		data->octets = cnt;
	}
	if(macMT7530GetPortTxPktsCnt(PortId, &cnt) == 0){
		data->packets = cnt;
	}

	if(macMT7530GetPortTxBroadPktsCnt(PortId, &cnt) == 0){
		data->broadcastPkts = cnt;
	}
	if(macMT7530GetPortTxMultiPktsCnt(PortId, &cnt) == 0){
		data->multicastPkts = cnt;
	}
	if(macMT7530GetPortTxCRCPktsCnt(PortId, &cnt) == 0){
		data->crcErroredPkts = cnt;
	}
	data->undersizePkts = 0;

	if(macMT7530GetPortTxOverSizePktsCnt2(PortId, &cnt) == 0)
		data->oversizePkts = cnt;
	
	if(macMT7530GetPortTx64PktsCnt(PortId, &cnt) == 0){
		data->pkts64Octets = cnt;
	}
	if(macMT7530GetPortTx127PktsCnt(PortId, &cnt) == 0){
		data->pkts127Octets = cnt;
	}
	if(macMT7530GetPortTx255PktsCnt(PortId, &cnt) == 0){
		data->pkts255Octets = cnt;
	}
	if(macMT7530GetPortTx511PktsCnt(PortId, &cnt) == 0){
		data->pkts511Octets = cnt;
	}
	if(macMT7530GetPortTx1023PktsCnt(PortId, &cnt) == 0){
		data->pkts1023Octets = cnt;
	}
	if(macMT7530GetPortTx1518PktsCnt(PortId, &cnt) == 0){
		data->pkts1518Octets = cnt;
	}	

	return 0;
}

int getEn8811PortRXCnt(EthFramePmStreamCounters_t *data)
{
	ECNT_TRAFFIC_WAN_RX_STATISTICS rx_stats;
	if(data == NULL)
	{
	    omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  data is NULL fail\n",__FUNCTION__,__LINE__);
	    return -1;
	}

	memset(&rx_stats, 0x0, sizeof(rx_stats));
	
	if(blapi_traffic_get_hsgmii_lan_rx_statistics(&rx_stats,3) < 0)
	{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]blapi_traffic_get_hsgmii_lan_rx_statistics fail.\n",__FUNCTION__,__LINE__);
		return -1;
	}
	data->dropEvents = rx_stats.drop_cnt;
	data->octets = rx_stats.frame_len;
	data->packets = rx_stats.frame_cnt;
	data->broadcastPkts = rx_stats.broadcast;
	data->multicastPkts = rx_stats.multicast;
	data->crcErroredPkts = rx_stats.crc;
	data->undersizePkts = rx_stats.undersize;
	data->oversizePkts = rx_stats.oversize;
	data->pkts64Octets = rx_stats.eq_64;
	data->pkts127Octets = rx_stats.from_65_to_127;
	data->pkts255Octets = rx_stats.from_128_to_255;
	data->pkts511Octets = rx_stats.from_256_to_511;
	data->pkts1023Octets = rx_stats.from_512_to_1023;
	data->pkts1518Octets = rx_stats.from_1024_to_1518;

	return 0;
}

int getEn8811PortTXCnt(EthFramePmStreamCounters_t *data)
{
	ECNT_TRAFFIC_WAN_TX_STATISTICS tx_stats;

	if(data == NULL)
	{
	    omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  data is NULL fail\n",__FUNCTION__,__LINE__);
	    return -1;
	}

	memset(&tx_stats, 0x0, sizeof(tx_stats));
	
	if(blapi_traffic_get_hsgmii_lan_tx_statistics(&tx_stats,3) < 0)
	{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]blapi_traffic_get_hsgmii_lan_tx_statistics fail.\n",__FUNCTION__,__LINE__);
		return -1;
	}
	data->dropEvents = tx_stats.drop_cnt;
	data->octets = tx_stats.frame_len;
	data->packets = tx_stats.frame_cnt;
	data->broadcastPkts = tx_stats.broadcast;
	data->multicastPkts = tx_stats.multicast;
	data->crcErroredPkts = 0;
	data->undersizePkts = 0;
	data->oversizePkts = 0;
	data->pkts64Octets = tx_stats.eq_64;
	data->pkts127Octets = tx_stats.from_65_to_127;
	data->pkts255Octets = tx_stats.from_128_to_255;
	data->pkts511Octets = tx_stats.from_256_to_511;
	data->pkts1023Octets = tx_stats.from_512_to_1023;
	data->pkts1518Octets = tx_stats.from_1024_to_1518;

	return 0;
}

int getVeipPortRxCnt(EthFramePmStreamCounters_t *data){
    int PortId = 0;
    uint32_t cnt = 0;
    
	if(data == NULL)
	{
	    omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  data is NULL fail\n",__FUNCTION__,__LINE__);
	    return -1;
	}
    
    memset(data, 0, sizeof(EthFramePmStreamCounters_t));
    for(PortId = 0; PortId < ETH_1G_UNI_TOTAL_NUM; PortId++){ 
        if(macMT7530GetPortRxLackDropPktCnt(PortId, &cnt) == 0){
		    data->dropEvents += cnt;
    	}
        
    	if(macMT7530GetPortRxOctetsCnt(PortId, &cnt) == 0){
    		data->octets += cnt;
    	}
        
    	if(macMT7530GetPortRxPktsCnt(PortId, &cnt) == 0){
    		data->packets += cnt;
    	}

    	if(macMT7530GetPortRxBroadPktsCnt(PortId, &cnt) == 0){
    		data->broadcastPkts += cnt;
    	}
        
    	if(macMT7530GetPortRxMultiPktsCnt(PortId, &cnt) == 0){
    		data->multicastPkts += cnt;
    	}
        
    	if(macMT7530GetPortRxCRCPktsCnt(PortId, &cnt) == 0){
    		data->crcErroredPkts += cnt;
    	}
        
    	if(macMT7530GetPortRxUnderSizePktsCnt(PortId, &cnt) == 0){
    		data->undersizePkts += cnt;
    	}
        
    	if(macMT7530GetPortRxOverSizePktsCnt(PortId, &cnt) == 0){
    		data->oversizePkts += cnt;
    	}
        
    	if(macMT7530GetPortRx64PktsCnt(PortId, &cnt) == 0){
    		data->pkts64Octets += cnt;
    	}
        
    	if(macMT7530GetPortRx127PktsCnt(PortId, &cnt) == 0){
    		data->pkts127Octets += cnt;
    	}
        
    	if(macMT7530GetPortRx255PktsCnt(PortId, &cnt) == 0){
    		data->pkts255Octets += cnt;
    	}
        
    	if(macMT7530GetPortRx511PktsCnt(PortId, &cnt) == 0){
    		data->pkts511Octets += cnt;
    	}
        
    	if(macMT7530GetPortRx1023PktsCnt(PortId, &cnt) == 0){
    		data->pkts1023Octets += cnt;
    	}
        
    	if(macMT7530GetPortRx1518PktsCnt(PortId, &cnt) == 0){
    		data->pkts1518Octets += cnt;
    	}
    }
    
    return 0;
}

int getVeipPortTxCnt(EthFramePmStreamCounters_t *data){
    int PortId = 0;
    uint32_t cnt = 0;

    if(data == NULL)
	{
	    omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  data is NULL fail\n",__FUNCTION__,__LINE__);
	    return -1;
	}

    memset(data, 0, sizeof(EthFramePmStreamCounters_t));
    
    for(PortId = 0; PortId < ETH_1G_UNI_TOTAL_NUM; PortId++){ 
    	if(macMT7530GetPortTxOctetsCnt(PortId, &cnt) == 0){
    		data->octets += cnt;
    	}
        
    	if(macMT7530GetPortTxPktsCnt(PortId, &cnt) == 0){
    		data->packets += cnt;
    	}

    	if(macMT7530GetPortTxBroadPktsCnt(PortId, &cnt) == 0){
    		data->broadcastPkts += cnt;
    	}
        
    	if(macMT7530GetPortTxMultiPktsCnt(PortId, &cnt) == 0){
    		data->multicastPkts += cnt;
    	}
        
    	if(macMT7530GetPortTxCRCPktsCnt(PortId, &cnt) == 0){
    		data->crcErroredPkts += cnt;
    	}
    	
    	if(macMT7530GetPortTx64PktsCnt(PortId, &cnt) == 0){
    		data->pkts64Octets += cnt;
    	}
        
    	if(macMT7530GetPortTx127PktsCnt(PortId, &cnt) == 0){
    		data->pkts127Octets += cnt;
    	}
        
    	if(macMT7530GetPortTx255PktsCnt(PortId, &cnt) == 0){
    		data->pkts255Octets += cnt;
    	}
        
    	if(macMT7530GetPortTx511PktsCnt(PortId, &cnt) == 0){
    		data->pkts511Octets += cnt;
    	}
        
    	if(macMT7530GetPortTx1023PktsCnt(PortId, &cnt) == 0){
    		data->pkts1023Octets += cnt;
    	}
        
    	if(macMT7530GetPortTx1518PktsCnt(PortId, &cnt) == 0){
    		data->pkts1518Octets += cnt;
    	}        
    }

    return 0;
}


int get_eth_frame_up_port_data(EthFramePmStreamCounters_t *data, uint16_t portId)
{
	uint32_t ifcType = 0;
	uint32_t tempPortId = 0;
    uint8_t mbpcdTpType = 0;    //mac bridge port configuration data TP type
    int i = 0, j = 0;

	if(data == NULL){
		return -1;
	}
    if(getMacBridgePortInstType(portId, &mbpcdTpType) != -1){
        if(mbpcdTpType == OMCI_MAC_BRIDGE_PORT_VEIP){
            if(getVeipPortRxCnt(data) != 0){
                return -1;
            }
            
            return 0;
        }
    }
	
	for(i = 0; i < MAX_GEM_PORT_NUM; i++){
		if(ani_uni_port[i].valid && ani_uni_port[i].index == portId){
			ifcType = ani_uni_port[i].ifaceType;
			break;
		}
	}
	if(i == MAX_GEM_PORT_NUM){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d] exceeded the max gemport num\n", __FUNCTION__, __LINE__);
		return -1;
	}
	
	if((ifcType != PM_LAN_INTERFACE_0) && (ifcType != PM_WAN_INTERFACE_1) ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]]->ifcType =%d fail\n", __FUNCTION__, __LINE__, ifcType);
		return -1;
	}

	/*get all port and caculate PM counter*/
	if(ifcType == PM_LAN_INTERFACE_0){//LAN port
		tempPortId = ani_uni_port[i].lan_portId-1;
		if(tempPortId == 6)
        {
        	if(getMacMT7530PortTXCnt(data, tempPortId)!= 0){
				return -1;
        	}
        }
        else
        {
        	if(pSystemCap->ethType[tempPortId] == UNIT_TYPE_ETHER_2500) {
				if(getEn8811PortRXCnt(data) != 0) {
					return -1;
        		}
        	}
			else{
        		if(getMacMT7530PortRXCnt(data, tempPortId)!= 0){
					return -1;
        		}
        	}
        }
	}else if(ifcType == PM_WAN_INTERFACE_1){//gem port
		for(j = 0; j< ani_uni_port[i].gemNum; j++){
			tempPortId = ani_uni_port[i].gemPortList[j];
		}
#if 0
		if(PonApi_PonTestCmd_Get(&getEntry) == EXEC_OK){
			pm->dropEvents += getEntry.value1;
			pm->octets += getEntry.value1;
			pm->packets += getEntry.value1;
			pm->broadcastPkts += getEntry.value1;
			pm->multicastPkts += getEntry.value1;
			pm->crcErroredPkts += getEntry.value1;
			pm->undersizePkts += getEntry.value1;
			pm->oversizePkts += getEntry.value1;
			pm->pkts64Octets += getEntry.value1;
			pm->pkts127Octets += getEntry.value1;
			pm->pkts255Octets += getEntry.value1;
			pm->pkts511Octets += getEntry.value1;
			pm->pkts1023Octets += getEntry.value1;
			pm->pkts1518Octets += getEntry.value1;
		}
#endif
	}else{
		//nothing
	}
	return 0;
}


int get_eth_frame_up_pm_history_data(pm_history_data_list_ptr pm_list, uint8_t syncFlag)
{
    EthFramePmStreamCounters_t eth_frame_up = {0};

    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(get_eth_frame_up_port_data(&eth_frame_up, pm_list->instId) != 0)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]->get_mac_br_port_data fail.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(syncFlag)
    {
        pm_list->pm_data.eth_frame_pm_up.interEndTime= pmIntervalTimes;
    	pm_list->pm_data.eth_frame_pm_up.dropEvent= (uint32_t)(eth_frame_up.dropEvents- pm_list->pm_prev_data.ethFrameUp.dropEvents);
    	pm_list->pm_data.eth_frame_pm_up.octets= (uint32_t)(eth_frame_up.octets- pm_list->pm_prev_data.ethFrameUp.octets);
    	pm_list->pm_data.eth_frame_pm_up.packets= (uint32_t)(eth_frame_up.packets- pm_list->pm_prev_data.ethFrameUp.packets);
        pm_list->pm_data.eth_frame_pm_up.broadPackets= (uint32_t)(eth_frame_up.broadcastPkts- pm_list->pm_prev_data.ethFrameUp.broadcastPkts);
        pm_list->pm_data.eth_frame_pm_up.multiPackets= (uint32_t)(eth_frame_up.multicastPkts- pm_list->pm_prev_data.ethFrameUp.multicastPkts);
        pm_list->pm_data.eth_frame_pm_up.crcErrPackets= (uint32_t)(eth_frame_up.crcErroredPkts- pm_list->pm_prev_data.ethFrameUp.crcErroredPkts);
    	pm_list->pm_data.eth_frame_pm_up.underPackets= (uint32_t)(eth_frame_up.undersizePkts- pm_list->pm_prev_data.ethFrameUp.undersizePkts);
    	pm_list->pm_data.eth_frame_pm_up.overPackets= (uint32_t)(eth_frame_up.oversizePkts- pm_list->pm_prev_data.ethFrameUp.oversizePkts);
        pm_list->pm_data.eth_frame_pm_up.packets64= (uint32_t)(eth_frame_up.pkts64Octets- pm_list->pm_prev_data.ethFrameUp.pkts64Octets);
        pm_list->pm_data.eth_frame_pm_up.packets65to127=(uint32_t)(eth_frame_up.pkts127Octets- pm_list->pm_prev_data.ethFrameUp.pkts127Octets);
        pm_list->pm_data.eth_frame_pm_up.packets128to255= (uint32_t)(eth_frame_up.pkts255Octets- pm_list->pm_prev_data.ethFrameUp.pkts255Octets);
    	pm_list->pm_data.eth_frame_pm_up.packets256to511= (uint32_t)(eth_frame_up.pkts511Octets- pm_list->pm_prev_data.ethFrameUp.pkts511Octets);
    	pm_list->pm_data.eth_frame_pm_up.packets512to1023= (uint32_t)(eth_frame_up.pkts1023Octets- pm_list->pm_prev_data.ethFrameUp.pkts1023Octets);
        pm_list->pm_data.eth_frame_pm_up.packets1024to1518= (uint32_t)(eth_frame_up.pkts1518Octets- pm_list->pm_prev_data.ethFrameUp.pkts1518Octets);

        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->dropEvent = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.eth_frame_pm_up.dropEvent);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->octets = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.eth_frame_pm_up.octets);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->packets = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.eth_frame_pm_up.packets);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->broadPackets = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.eth_frame_pm_up.broadPackets);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->multiPackets = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_data.eth_frame_pm_up.multiPackets);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->crcErrPackets = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.eth_frame_pm_up.crcErrPackets);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->underPackets = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.eth_frame_pm_up.underPackets);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->overPackets = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.eth_frame_pm_up.overPackets);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->packets64 = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.eth_frame_pm_up.packets64);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->packets65to127 = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_data.eth_frame_pm_up.packets65to127);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->packets128to255 = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.eth_frame_pm_up.packets128to255);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->packets256to511 = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.eth_frame_pm_up.packets256to511);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->packets512to1023 = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.eth_frame_pm_up.packets512to1023);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->packets1024to1518 = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.eth_frame_pm_up.packets1024to1518);
    }

    memcpy(&pm_list->pm_prev_data.ethFrameUp, &eth_frame_up, sizeof(EthFramePmStreamCounters_t));

    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->dropEvent = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.ethFrameUp.dropEvents);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->octets = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.ethFrameUp.octets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->packets = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.ethFrameUp.packets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->broadPackets = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.ethFrameUp.broadcastPkts);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->multiPackets = 0x%llx\n",__FUNCTION__,__LINE__,pm_list->pm_prev_data.ethFrameUp.multicastPkts);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->crcErrPackets = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.ethFrameUp.crcErroredPkts);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->underPackets = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.ethFrameUp.undersizePkts);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->overPackets = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.ethFrameUp.oversizePkts);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->packets64 = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.ethFrameUp.pkts64Octets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->packets65to127 = 0x%llx\n",__FUNCTION__,__LINE__,pm_list->pm_prev_data.ethFrameUp.pkts127Octets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->packets128to255 = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.ethFrameUp.pkts255Octets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->packets256to511 = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.ethFrameUp.pkts511Octets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->packets512to1023 = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.ethFrameUp.pkts1023Octets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->packets1024to1518 = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.ethFrameUp.pkts1518Octets);
	
    return 0;
}

int omci_me_eth_frame_up_pm_history_get_curr_op(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
    omci_eth_frame_pm_his_up_ptr eth_frame_up_pm_new = NULL;
    EthFramePmStreamCounters_t eth_frame_up = {0};

    if(me_entry == NULL || me_info == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]pointer is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    eth_frame_up_pm_new = (omci_eth_frame_pm_his_up_ptr)me_info->attributes;
    if(eth_frame_up_pm_new == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]me info attribute is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(get_eth_frame_up_port_data(&eth_frame_up, me_info->inst_id) != 0)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]->get_mac_br_port_data fail.\n",__FUNCTION__,__LINE__);
        return -1;
    }

	eth_frame_up_pm_new->interEndTime= pmIntervalTimes;
	eth_frame_up_pm_new->dropEvent= (uint32_t)eth_frame_up.dropEvents;
	eth_frame_up_pm_new->octets= (uint32_t)eth_frame_up.octets;
	eth_frame_up_pm_new->packets= (uint32_t)eth_frame_up.packets;
	eth_frame_up_pm_new->broadPackets= (uint32_t)eth_frame_up.broadcastPkts;
	eth_frame_up_pm_new->multiPackets= (uint32_t)eth_frame_up.multicastPkts;
	eth_frame_up_pm_new->crcErrPackets= (uint32_t)eth_frame_up.crcErroredPkts;
	eth_frame_up_pm_new->underPackets= (uint32_t)eth_frame_up.undersizePkts;
	eth_frame_up_pm_new->overPackets= (uint32_t)eth_frame_up.oversizePkts;
	eth_frame_up_pm_new->packets64= (uint32_t)eth_frame_up.pkts64Octets;
	eth_frame_up_pm_new->packets65to127= (uint32_t)eth_frame_up.pkts127Octets;
	eth_frame_up_pm_new->packets128to255= (uint32_t)eth_frame_up.pkts255Octets;
	eth_frame_up_pm_new->packets256to511= (uint32_t)eth_frame_up.pkts511Octets;
	eth_frame_up_pm_new->packets512to1023= (uint32_t)eth_frame_up.pkts1023Octets;
	eth_frame_up_pm_new->packets1024to1518= (uint32_t)eth_frame_up.pkts1518Octets;
	

	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->dropEvent = 0x%x\n",__FUNCTION__,__LINE__, eth_frame_up_pm_new->dropEvent);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->octets = 0x%x\n",__FUNCTION__,__LINE__, eth_frame_up_pm_new->octets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->packets = 0x%x\n",__FUNCTION__,__LINE__, eth_frame_up_pm_new->packets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->broadPackets = 0x%x\n",__FUNCTION__,__LINE__, eth_frame_up_pm_new->broadPackets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->multiPackets = 0x%x\n",__FUNCTION__,__LINE__,eth_frame_up_pm_new->multiPackets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->crcErrPackets = 0x%x\n",__FUNCTION__,__LINE__, eth_frame_up_pm_new->crcErrPackets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->underPackets = 0x%x\n",__FUNCTION__,__LINE__, eth_frame_up_pm_new->underPackets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->overPackets = 0x%x\n",__FUNCTION__,__LINE__, eth_frame_up_pm_new->overPackets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->packets64 = 0x%x\n",__FUNCTION__,__LINE__, eth_frame_up_pm_new->packets64);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->packets65to127 = 0x%x\n",__FUNCTION__,__LINE__,eth_frame_up_pm_new->packets65to127);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->packets128to255 = 0x%x\n",__FUNCTION__,__LINE__, eth_frame_up_pm_new->packets128to255);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->packets256to511 = 0x%x\n",__FUNCTION__,__LINE__, eth_frame_up_pm_new->packets256to511);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->packets512to1023 = 0x%x\n",__FUNCTION__,__LINE__, eth_frame_up_pm_new->packets512to1023);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->packets1024to1518 = 0x%x\n",__FUNCTION__,__LINE__, eth_frame_up_pm_new->packets1024to1518);

    return 0;
}


int omci_me_eth_frame_up_pm_history_notify(pm_history_data_list_ptr pm_list, omci_me_info_t threshold_info)
{
    enum{ ETH_FRAME_UP_PM_HISTORY_DATA_TCA_NUM = 4};
    omci_threshold_data_1_ptr threshold_data1 = NULL;
    int i = 0;
    uint32_t currentData[ETH_FRAME_UP_PM_HISTORY_DATA_TCA_NUM] = {0};
    static uint8_t reportFlag[ETH_FRAME_UP_PM_HISTORY_DATA_TCA_NUM] = {0};
    uint8_t alarm_num[ETH_FRAME_UP_PM_HISTORY_DATA_TCA_NUM] = {0, 1, 2, 3};
    tca_notify_info_t tca_info = {0};
    EthFramePmStreamCounters_t eth_frame_up = {0};
    
    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(omci_pm_is_end_of_interval_time())
    {
        memset(reportFlag, 0, sizeof(reportFlag));
        return 0;
    }
    if(threshold_info.class_id != OMCI_CLASS_ID_THRESHOLD_DATA1){
        return 0;
    }

	threshold_data1 =  (omci_threshold_data_1_ptr)threshold_info.attributes;
	if(threshold_data1 == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  threshold value is NULL \n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(get_eth_frame_up_port_data(&eth_frame_up, pm_list->instId) != 0)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]->get_mac_br_port_data fail.\n",__FUNCTION__,__LINE__);
        return -1;
    }
    /*monitor 15min interval tca attribute value*/
	currentData[0]= (uint32_t)(eth_frame_up.dropEvents - pm_list->pm_prev_data.ethFrameUp.dropEvents);
	currentData[1]= (uint32_t)(eth_frame_up.crcErroredPkts - pm_list->pm_prev_data.ethFrameUp.crcErroredPkts);
	currentData[2]= (uint32_t)(eth_frame_up.undersizePkts - pm_list->pm_prev_data.ethFrameUp.undersizePkts);
	currentData[3]= (uint32_t)(eth_frame_up.oversizePkts - pm_list->pm_prev_data.ethFrameUp.oversizePkts);    

    for(i = 0; i < ETH_FRAME_UP_PM_HISTORY_DATA_TCA_NUM; i++)
    {
        tca_info.classId = pm_list->classId;
        tca_info.instId = pm_list->instId;
        tca_info.currentData = currentData[i];
        tca_info.threshold = threshold_data1->thresholdValue[i];
        tca_info.alarm_num = alarm_num[i];
        tca_info.reportFlag = reportFlag[i];

        reportFlag[i] = omci_pm_report_alarm_by_tca_info(tca_info, 0);
	}

	return 0;
    
}


omci_me_func_t omci_me_eth_frame_pm_his_up_op ={
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_set_op,
	omci_me_general_pm_history_get_op,
	omci_me_eth_frame_up_pm_history_get_curr_op,
};

omci_eth_frame_pm_his_up_t omci_eth_frame_pm_his_up_attr_data = {0};

omci_attr_t omci_eth_frame_pm_his_up_attr ={
	(uint8_t *)&omci_eth_frame_pm_his_up_attr_data,
	sizeof(omci_eth_frame_pm_his_up_attr_data),
};

/*******************************************************************************************************************************
9.3.31 ethernet frame performance monitoring history data downstream

********************************************************************************************************************************/
omci_attr_dscp_t omci_attr_eth_frame_pm_his_down_op[]={
	{0, "Managed entity id",        2 , ATTR_ACCESS_R_SET_CREATE ,  ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,   &generalAttrFunc},
	{1, "Interval end time",        1 , ATTR_ACCESS_R ,             ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,   &generalAttrFunc},
	{2, "Threshold data 1/2 id",    2 , ATTR_ACCESS_R_W_SET_CREATE, ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,   &generalAttrFunc},
	{3, "Drop events",              4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,   &generalAttrFunc},
	{4, "Octets",                   4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,   &generalAttrFunc},
	{5, "Packets",                  4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,   &generalAttrFunc},
	{6, "Broadcast packets",        4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,   &generalAttrFunc},
	{7, "Multicast packets",        4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,   &generalAttrFunc},
	{8, "CRC errored packets",      4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,   &generalAttrFunc},	
	{9, "Undersize packets",        4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,   &generalAttrFunc},
	{10,"Oversize packets",         4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,   &generalAttrFunc},
	{11,"Packets 64 octets",        4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,   &generalAttrFunc},
	{12,"Packets 65~127 octets",    4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,   &generalAttrFunc},
	{13,"Packets 128~255 octets",   4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,   &generalAttrFunc},
	{14,"Packets 256~511 octets",   4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,   &generalAttrFunc},
	{15,"Packets 512~1023 octets",  4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,   &generalAttrFunc},
	{16,"Packets 1024~1518 octets", 4 , ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,   &generalAttrFunc},
	{255, 	"", 					0 , 0,                          0,                           0,                     NULL}
};


int get_eth_frame_down_port_data(EthFramePmStreamCounters_t *data, uint16_t portId)
{
	uint32_t ifcType = 0;
	uint32_t tempPortId = 0;
	int i = 0, j=0;
    uint8_t mbpcdTpType = 0;//mac bridge port configuration data TP type
#ifndef BSP_BUILD
	ECNT_TRAFFIC_WAN_RX_STATISTICS gdma2Stats = {0};
#endif
	if(data == NULL){
		return -1;
	}

     if(getMacBridgePortInstType(portId, &mbpcdTpType) != -1){
        if(mbpcdTpType == OMCI_MAC_BRIDGE_PORT_VEIP){
            if(getVeipPortTxCnt(data) != 0){
                return -1;
            }
            
            return 0;
        }
    }

	for(i = 0; i < MAX_GEM_PORT_NUM; i++){
		if(ani_uni_port[i].valid && ani_uni_port[i].index == portId){
			ifcType = ani_uni_port[i].ifaceType;
			break;
		}
	}
	if(i == MAX_GEM_PORT_NUM){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]can not find ifcType\n", __FUNCTION__, __LINE__);
		return -1;
	}
		
	if((ifcType != PM_LAN_INTERFACE_0) && (ifcType != PM_WAN_INTERFACE_1) ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]->ifcType =%d fail\n", __FUNCTION__, __LINE__, ifcType);
		return -1;
	}
	
	/*get all port and caculate PM counter*/
		
	if(ifcType == PM_LAN_INTERFACE_0){//LAN port
		tempPortId = ani_uni_port[i].lan_portId-1;
		if(tempPortId == 6)
        {
		#ifndef BSP_BUILD
			if(blapi_traffic_get_wan_rx_statistics(&gdma2Stats)!= 0){
				return -1;
			}
			data->dropEvents 		= gdma2Stats.drop_cnt;
			data->octets 			= gdma2Stats.frame_len;
			data->packets 		= gdma2Stats.frame_cnt;
			data->broadcastPkts 	= gdma2Stats.broadcast;
			data->multicastPkts 	= gdma2Stats.multicast;
			data->crcErroredPkts 	= gdma2Stats.crc;
			data->undersizePkts 	= gdma2Stats.undersize;
			data->oversizePkts 	= gdma2Stats.oversize;
			data->pkts64Octets 	= gdma2Stats.eq_64;
			data->pkts127Octets 	= gdma2Stats.from_65_to_127;
			data->pkts255Octets 	= gdma2Stats.from_128_to_255;
			data->pkts511Octets 	= gdma2Stats.from_256_to_511;
			data->pkts1023Octets 	= gdma2Stats.from_512_to_1023;
			data->pkts1518Octets 	= gdma2Stats.from_1024_to_1518;
		#endif
		}
        else
        {
        	if(pSystemCap->ethType[tempPortId] == UNIT_TYPE_ETHER_2500) {
				if(getEn8811PortTXCnt(data) != 0) {
					return -1;
				}
        	}
			else {
        		if(getMacMT7530PortTXCnt(data,tempPortId) != 0){
					return -1;
        		}
        	}
		}
	}else if(ifcType == PM_WAN_INTERFACE_1){//gem port
		for(j = 0; j< ani_uni_port[i].gemNum; j++){
			tempPortId = ani_uni_port[i].gemPortList[j];
		}
#if 0		
		if(PonApi_PonTestCmd_Get(&getEntry) == EXEC_OK){
			pm->dropEvents += getEntry.value1;
			pm->octets += getEntry.value1;
			pm->packets += getEntry.value1;
			pm->broadcastPkts += getEntry.value1;
			pm->multicastPkts += getEntry.value1;
			pm->crcErroredPkts += getEntry.value1;
			pm->undersizePkts += getEntry.value1;
			pm->oversizePkts += getEntry.value1;
			pm->pkts64Octets += getEntry.value1;
			pm->pkts127Octets += getEntry.value1;
			pm->pkts255Octets += getEntry.value1;
			pm->pkts511Octets += getEntry.value1;
			pm->pkts1023Octets += getEntry.value1;
			pm->pkts1518Octets += getEntry.value1;
		}
#endif
		}else{
			//nothing
		}
	return 0;
}


int get_eth_frame_down_pm_history_data(pm_history_data_list_ptr pm_list, uint8_t syncFlag)
{
    EthFramePmStreamCounters_t eth_frame_down = {0};

    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(get_eth_frame_down_port_data(&eth_frame_down, pm_list->instId) != 0)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]->get_mac_br_port_data fail.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(syncFlag)
    {
        pm_list->pm_data.eth_frame_pm_down.interEndTime= pmIntervalTimes;
    	pm_list->pm_data.eth_frame_pm_down.dropEvent= eth_frame_down.dropEvents- pm_list->pm_prev_data.ethFrameDown.dropEvents;
    	pm_list->pm_data.eth_frame_pm_down.octets= eth_frame_down.octets- pm_list->pm_prev_data.ethFrameDown.octets;
    	pm_list->pm_data.eth_frame_pm_down.packets= eth_frame_down.packets- pm_list->pm_prev_data.ethFrameDown.packets;
        pm_list->pm_data.eth_frame_pm_down.broadPackets= eth_frame_down.broadcastPkts- pm_list->pm_prev_data.ethFrameDown.broadcastPkts;
        pm_list->pm_data.eth_frame_pm_down.multiPackets= eth_frame_down.multicastPkts- pm_list->pm_prev_data.ethFrameDown.multicastPkts;
        pm_list->pm_data.eth_frame_pm_down.crcErrPackets= eth_frame_down.crcErroredPkts- pm_list->pm_prev_data.ethFrameDown.crcErroredPkts;
    	pm_list->pm_data.eth_frame_pm_down.underPackets= eth_frame_down.undersizePkts- pm_list->pm_prev_data.ethFrameDown.undersizePkts;
    	pm_list->pm_data.eth_frame_pm_down.overPackets= eth_frame_down.oversizePkts- pm_list->pm_prev_data.ethFrameDown.oversizePkts;
        pm_list->pm_data.eth_frame_pm_down.packets64= eth_frame_down.pkts64Octets- pm_list->pm_prev_data.ethFrameDown.pkts64Octets;
        pm_list->pm_data.eth_frame_pm_down.packets65to127= eth_frame_down.pkts127Octets- pm_list->pm_prev_data.ethFrameDown.pkts127Octets;
        pm_list->pm_data.eth_frame_pm_down.packets128to255= eth_frame_down.pkts255Octets- pm_list->pm_prev_data.ethFrameDown.pkts255Octets;
    	pm_list->pm_data.eth_frame_pm_down.packets256to511= eth_frame_down.pkts511Octets- pm_list->pm_prev_data.ethFrameDown.pkts511Octets;
    	pm_list->pm_data.eth_frame_pm_down.packets512to1023= eth_frame_down.pkts1023Octets- pm_list->pm_prev_data.ethFrameDown.pkts1023Octets;
        pm_list->pm_data.eth_frame_pm_down.packets1024to1518= eth_frame_down.pkts1518Octets- pm_list->pm_prev_data.ethFrameDown.pkts1518Octets;

        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->dropEvent = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.eth_frame_pm_down.dropEvent);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->octets = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.eth_frame_pm_down.octets);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->packets = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.eth_frame_pm_down.packets);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->broadPackets = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.eth_frame_pm_down.broadPackets);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->multiPackets = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_data.eth_frame_pm_down.multiPackets);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->crcErrPackets = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.eth_frame_pm_down.crcErrPackets);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->underPackets = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.eth_frame_pm_down.underPackets);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->overPackets = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.eth_frame_pm_down.overPackets);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->packets64 = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.eth_frame_pm_down.packets64);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->packets65to127 = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_data.eth_frame_pm_down.packets65to127);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->packets128to255 = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.eth_frame_pm_down.packets128to255);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->packets256to511 = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.eth_frame_pm_down.packets256to511);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->packets512to1023 = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.eth_frame_pm_down.packets512to1023);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->packets1024to1518 = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.eth_frame_pm_down.packets1024to1518);
    }

    memcpy(&pm_list->pm_prev_data.ethFrameDown, &eth_frame_down, sizeof(EthFramePmStreamCounters_t));

    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->dropEvent = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.ethFrameDown.dropEvents);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->octets = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.ethFrameDown.octets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->packets = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.ethFrameDown.packets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->broadPackets = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.ethFrameDown.broadcastPkts);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->multiPackets = 0x%llx\n",__FUNCTION__,__LINE__,pm_list->pm_prev_data.ethFrameDown.multicastPkts);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->crcErrPackets = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.ethFrameDown.crcErroredPkts);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->underPackets = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.ethFrameDown.undersizePkts);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->overPackets = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.ethFrameDown.oversizePkts);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->packets64 = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.ethFrameDown.pkts64Octets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->packets65to127 = 0x%llx\n",__FUNCTION__,__LINE__,pm_list->pm_prev_data.ethFrameDown.pkts127Octets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->packets128to255 = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.ethFrameDown.pkts255Octets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->packets256to511 = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.ethFrameDown.pkts511Octets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->packets512to1023 = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.ethFrameDown.pkts1023Octets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->packets1024to1518 = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.ethFrameDown.pkts1518Octets);
	
    return 0;
}

int omci_me_eth_frame_down_pm_history_get_curr_op(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
    omci_eth_frame_pm_his_up_ptr eth_frame_down_pm_new = NULL;
    EthFramePmStreamCounters_t eth_frame_down = {0};

    if(me_entry == NULL || me_info == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]pointer is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    eth_frame_down_pm_new = (omci_eth_frame_pm_his_up_ptr)me_info->attributes;
    if(eth_frame_down_pm_new == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]me info attribute is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(get_eth_frame_down_port_data(&eth_frame_down, me_info->inst_id) != 0)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]->get_mac_br_port_data fail.\n",__FUNCTION__,__LINE__);
        return -1;
    }

	eth_frame_down_pm_new->interEndTime= pmIntervalTimes;
	eth_frame_down_pm_new->dropEvent= eth_frame_down.dropEvents;
	eth_frame_down_pm_new->octets= eth_frame_down.octets;
	eth_frame_down_pm_new->packets= eth_frame_down.packets;
	eth_frame_down_pm_new->broadPackets= eth_frame_down.broadcastPkts;
	eth_frame_down_pm_new->multiPackets= eth_frame_down.multicastPkts;
	eth_frame_down_pm_new->crcErrPackets= eth_frame_down.crcErroredPkts;
	eth_frame_down_pm_new->underPackets= eth_frame_down.undersizePkts;
	eth_frame_down_pm_new->overPackets= eth_frame_down.oversizePkts;
	eth_frame_down_pm_new->packets64= eth_frame_down.pkts64Octets;
	eth_frame_down_pm_new->packets65to127= eth_frame_down.pkts127Octets;
	eth_frame_down_pm_new->packets128to255= eth_frame_down.pkts255Octets;
	eth_frame_down_pm_new->packets256to511= eth_frame_down.pkts511Octets;
	eth_frame_down_pm_new->packets512to1023= eth_frame_down.pkts1023Octets;
	eth_frame_down_pm_new->packets1024to1518= eth_frame_down.pkts1518Octets;
	

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d]->dropEvent = 0x%x\n",__FUNCTION__,__LINE__, eth_frame_down_pm_new->dropEvent);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d]->octets = 0x%x\n",__FUNCTION__,__LINE__, eth_frame_down_pm_new->octets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d]->packets = 0x%x\n",__FUNCTION__,__LINE__, eth_frame_down_pm_new->packets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d]->broadPackets = 0x%x\n",__FUNCTION__,__LINE__, eth_frame_down_pm_new->broadPackets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d]->multiPackets = 0x%x\n",__FUNCTION__,__LINE__,eth_frame_down_pm_new->multiPackets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d]->crcErrPackets = 0x%x\n",__FUNCTION__,__LINE__, eth_frame_down_pm_new->crcErrPackets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d]->underPackets = 0x%x\n",__FUNCTION__,__LINE__, eth_frame_down_pm_new->underPackets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d]->overPackets = 0x%x\n",__FUNCTION__,__LINE__, eth_frame_down_pm_new->overPackets);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d]->packets64 = 0x%x\n",__FUNCTION__,__LINE__, eth_frame_down_pm_new->packets64);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d]->packets65to127 = 0x%x\n",__FUNCTION__,__LINE__,eth_frame_down_pm_new->packets65to127);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d]->packets128to255 = 0x%x\n",__FUNCTION__,__LINE__, eth_frame_down_pm_new->packets128to255);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d]->packets256to511 = 0x%x\n",__FUNCTION__,__LINE__, eth_frame_down_pm_new->packets256to511);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d]->packets512to1023 = 0x%x\n",__FUNCTION__,__LINE__, eth_frame_down_pm_new->packets512to1023);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d]->packets1024to1518 = 0x%x\n",__FUNCTION__,__LINE__, eth_frame_down_pm_new->packets1024to1518);

    return 0;
}


int omci_me_eth_frame_down_pm_history_notify(pm_history_data_list_ptr pm_list, omci_me_info_t threshold_info)
{
    enum{ ETH_FRAME_DOWN_PM_HISTORY_DATA_TCA_NUM = 4};
    omci_threshold_data_1_ptr threshold_data1 = NULL;
    int i = 0;
    uint32_t currentData[ETH_FRAME_DOWN_PM_HISTORY_DATA_TCA_NUM] = {0};
    static uint8_t reportFlag[ETH_FRAME_DOWN_PM_HISTORY_DATA_TCA_NUM] = {0};
    uint8_t alarm_num[ETH_FRAME_DOWN_PM_HISTORY_DATA_TCA_NUM] = {0, 1, 2, 3};
    tca_notify_info_t tca_info = {0};
    EthFramePmStreamCounters_t eth_frame_down = {0};
    
    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(omci_pm_is_end_of_interval_time())
    {
        memset(reportFlag, 0, sizeof(reportFlag));
        return 0;
    }
    if(threshold_info.class_id != OMCI_CLASS_ID_THRESHOLD_DATA1){
        return 0;
    }

	threshold_data1 =  (omci_threshold_data_1_ptr)threshold_info.attributes;
	if(threshold_data1 == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  threshold value is NULL \n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(get_eth_frame_down_port_data(&eth_frame_down, pm_list->instId) != 0)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]->get_mac_br_port_data fail.\n",__FUNCTION__,__LINE__);
        return -1;
    }
    /*monitor 15min interval tca attribute value*/
	currentData[0]= eth_frame_down.dropEvents - pm_list->pm_prev_data.ethFrameDown.dropEvents;
	currentData[1]= eth_frame_down.crcErroredPkts - pm_list->pm_prev_data.ethFrameDown.crcErroredPkts;
	currentData[2]= eth_frame_down.undersizePkts - pm_list->pm_prev_data.ethFrameDown.undersizePkts;
	currentData[3]= eth_frame_down.oversizePkts - pm_list->pm_prev_data.ethFrameDown.oversizePkts;    

    for(i = 0; i < ETH_FRAME_DOWN_PM_HISTORY_DATA_TCA_NUM; i++)
    {
        tca_info.classId = pm_list->classId;
        tca_info.instId = pm_list->instId;
        tca_info.currentData = currentData[i];
        tca_info.threshold = threshold_data1->thresholdValue[i];
        tca_info.alarm_num = alarm_num[i];
        tca_info.reportFlag = reportFlag[i];

        reportFlag[i] = omci_pm_report_alarm_by_tca_info(tca_info, 0);
	}

	return 0;
    
}


omci_me_func_t omci_me_eth_frame_pm_his_down_op ={
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_set_op,
	omci_me_general_pm_history_get_op,
	omci_me_eth_frame_down_pm_history_get_curr_op,
};

omci_eth_frame_pm_his_down_t omci_eth_frame_pm_his_down_attr_data = {0};

omci_attr_t omci_eth_frame_pm_his_down_attr ={
	(uint8_t *)&omci_eth_frame_pm_his_down_attr_data,
	sizeof(omci_eth_frame_pm_his_down_attr_data),
};


/*******************************************************************************************
**function name
	findMBPortInfo
**description:
	find mac bridge port information form list
 **retrun :
 	NULL:	not find
 	information node:	success
**parameter:
	instId:	9.3.4 instance id
********************************************************************************************/
mb_port_info_ptr findMBPortInfo(uint16_t instId){
	mb_port_info_ptr info_ptr = NULL;

	info_ptr = gMBPortInfo_ptr;
	while(info_ptr != NULL){
		if(info_ptr->instId == instId){
			return info_ptr;
		}
		info_ptr = info_ptr->next;
	}

	return NULL;	
}

/*******************************************************************************************
**function name
	addMBPortInfo
**description:
	add or modify mac bridge port information in list
 **retrun :
 	-1:	fail
 	0:	success
**parameter:
	info_ptr:	mac bridge port information
********************************************************************************************/
int addMBPortInfo(IN mb_port_info_ptr  info_ptr){
	mb_port_info_ptr new_info_ptr = NULL;
	mb_port_info_ptr temp_ptr = NULL;

	if(info_ptr == NULL)
		return -1;

	/*find mac port information form list*/
	temp_ptr = findMBPortInfo(info_ptr->instId);
	
	/*set new mac bridge port inromation*/
	
	if(temp_ptr != NULL){//find , modify
		info_ptr->next = temp_ptr->next;
		memcpy(temp_ptr, info_ptr, sizeof(mb_port_info_t));
		return 0;
	}
	
	/*no find , create new mac bridge port node*/	
	new_info_ptr = (mb_port_info_ptr)calloc(1 , sizeof(mb_port_info_t));
	if(new_info_ptr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n addMBPortInfo->calloc failure");
		return -1;
	}
	memcpy(new_info_ptr, info_ptr, sizeof(mb_port_info_t));
	new_info_ptr->next = NULL;

	/*add new node to list*/
	if(gMBPortInfo_ptr == NULL){
		gMBPortInfo_ptr = new_info_ptr;
		return 0;
	}

	temp_ptr = gMBPortInfo_ptr;
	while(temp_ptr->next != NULL){
		temp_ptr = temp_ptr->next;
	}
	temp_ptr->next = new_info_ptr;

	return 0;
}
/*******************************************************************************************
**function name
	delMBPortInfo
**description:
	del mac bridge port information node from list
 **retrun :
 	-1:	fail
 	0:	success
**parameter:
	instId:	9.3.4 instnace id
********************************************************************************************/
int delMBPortInfo(IN uint16_t instId){
	int ret = -1;
	mb_port_info_ptr info_ptr = NULL;
	mb_port_info_ptr pre_ptr = NULL;

	info_ptr = gMBPortInfo_ptr;
	pre_ptr = gMBPortInfo_ptr;
	while(info_ptr != NULL){
		if(info_ptr->instId == instId){
			if(info_ptr == gMBPortInfo_ptr){
				gMBPortInfo_ptr = info_ptr->next;
			}else{
				pre_ptr->next = info_ptr->next;
			}
			if(info_ptr != NULL){
				free(info_ptr);
				info_ptr = NULL;
			}
//			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n delMBPortInfo->find del success");
			break;
		}
		pre_ptr = info_ptr;
		info_ptr = info_ptr->next;
	}

	ret = 0;
//	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n delMBPortInfo->find or no find success");
//	displayMBPortInfo();//LHS DBG
	return ret;
}
/*******************************************************************************************
**function name
	clearMBPortInfo
**description:
	clear mac bridge port information list
 **retrun :
 	-1:	fail
 	0:	success
**parameter:
********************************************************************************************/
int clearMBPortInfo(void){
	mb_port_info_ptr info_ptr = NULL;
	mb_port_info_ptr temp_ptr = NULL;

	info_ptr = gMBPortInfo_ptr;
	while(info_ptr != NULL){
		temp_ptr = info_ptr->next;
		free(info_ptr);
		info_ptr = temp_ptr;
	}

	gMBPortInfo_ptr = NULL;
	return 0;
}

/*******************************************************************************************
**function name
	displayMBPortInfo
**description:
	display all mac bridge port information node from list
 **retrun :
 	-1:	fail
 	0:	success
**parameter:
********************************************************************************************/
void displayMBPortInfo(){
	mb_port_info_ptr info_ptr = NULL;
	int i = 0;
	
	info_ptr = gMBPortInfo_ptr;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n displayMBPortInfo->");
	while(info_ptr != NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n info_ptr->instId = 0x%02x",info_ptr->instId);
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n info_ptr->type = 0x%02x",info_ptr->type);
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n info_ptr->reserve = 0x%02x",info_ptr->reserve);
		for(i=0; i<MAX_MAC_BRIDGE_PORT_GEM_PORT_NUM; i++){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n info_ptr->gemlist[%d][0]=0x%02x,info_ptr->gemlist[%d][1]=0x%02x",i,info_ptr->gemlist[i][0],i, info_ptr->gemlist[i][1]);
		}
		info_ptr = info_ptr->next;
	}
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n");

	return;
}

/*******************************************************************************************
**function name
	
**description:
	clear mac bridge global infomation
 **retrun :
	0:	success
	-1: failure
**parameter:
********************************************************************************************/
int clearOmciMBInfo(void){
	int i = 0;
	pthread_mutex_lock(&omciSetMBPDevId);

	/*clear global validAniPortFlag variable*/
	for(i=0;i<MAX_OMCI_ANI_PORT_NUM;i++){
		validAniPortFlag[i][0] = 0;
		validAniPortFlag[i][1] = OMCI_INVALID_MAC_BRIDGE_PORT_FLAG;
	}
	pthread_mutex_unlock(&omciSetMBPDevId);
	/*clear global omci mac bridge port information*/
	clearMBPortInfo();

	return 0;	
}

/*******************************************************************************************
**function name
	getFreeOmciAniPortId
**description:
	get free omci ani port id
 **retrun :
 	1:	fail
 	0:	success
**parameter:
	omcAniPortId:	return ani port id
********************************************************************************************/
int getFreeOmciAniPortId(OUT uint16_t * omcAniPortId){
	int i = 0;
	int ret = OMCI_MAC_BRIDGE_PORT_FAIL;

	for(i=0; i<MAX_OMCI_ANI_PORT_NUM; i++){
		if(validAniPortFlag[i][OMCI_ANI_PORT_VALID_INDEX] == OMCI_INVALID_MAC_BRIDGE_PORT_FLAG){
			*omcAniPortId = i;
			ret = OMCI_MAC_BRIDGE_PORT_SUCCESS;
			break;
		} 
	}
	return ret;
}
/*******************************************************************************************
**function name
	findOmciAniPortId
**description:
	find omci ani port id
 **retrun :
 	1:	fail
 	0:	success
**parameter:
	instId:	9.3.4 instance id
	findFlag: 0:no find, 1:find
	omcAniPortId:find ani port id
********************************************************************************************/
int findOmciAniPortId(uint16_t instId, uint8_t *findFlag, uint16_t * omcAniPortId ){
	int i = 0;
	int ret = OMCI_MAC_BRIDGE_PORT_FAIL;

	if(findFlag == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "findFlag==NULL\n");
		goto end;
	}

	*findFlag = OMCI_NO_FIND_RULE;
	
	for(i=0; i<MAX_OMCI_ANI_PORT_NUM; i++){
		if((validAniPortFlag[i][OMCI_ANI_PORT_INST_ID_INDEX] == instId)
			&& (validAniPortFlag[i][OMCI_ANI_PORT_VALID_INDEX] == OMCI_VALID_MAC_BRIDGE_PORT_FLAG)){
			*findFlag = OMCI_FIND_RULE;
			*omcAniPortId = i;
			break;
		} 
	}
	
	ret = OMCI_MAC_BRIDGE_PORT_SUCCESS;	
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "findOmciAniPortId-->ret = 0x%02x, omcAniPortId=%d,findFlag=%d(find:1, not find:0)\n", ret,*omcAniPortId,*findFlag);
end:
	return ret;
}

/*******************************************************************************************************************************
general function

********************************************************************************************************************************/
/*******************************************************************************************
**function name
	handlePonIfc
**description:
	add or delete ANI interface, assign or unassign gemport to ANI interface
 **retrun :
	0:	success
	-1: failure
**parameter:
	ifcHandleType: action type
	index: ANI interface number(0~31)
	gemPortList: gemport list in this ANI interface
	validGemPortNum: valid gemport num
	instId: 9.3.4 instance id	
********************************************************************************************/

int handlePonIfc(uint8_t ifcHandleType, uint16_t index, uint16_t * gemPortList, uint8_t validGemPortNum, uint16_t instId){
	int ret = -1;
	int i = 0;
	mb_port_info_ptr info_ptr = NULL;
	struct XMCS_GemPortAssign_S gponGemAssign ;
	pthread_mutex_lock(&omciHandlePonIfc);
	
	if((index>=MAX_OMCI_ANI_PORT_NUM) || (validGemPortNum > MAX_MAC_BRIDGE_PORT_GEM_PORT_NUM)){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR," %s parameter error!\n", __FUNCTION__);
		ret = -1;
		goto end;
	}

	memset(&gponGemAssign, 0, sizeof(gponGemAssign));
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"%s ifcHandleType=%d,index=%d,validGemPortNum=%d, instId=%d\n", 
		__FUNCTION__,ifcHandleType,index,validGemPortNum,instId);

	switch(ifcHandleType){
		case GPON_HANDLE_PON_IFC_MODIFY:
		case GPON_HANDLE_PON_IFC_UNASSIGN:
			gponGemAssign.entryNum = 0 ;
			for(i=0 ; i < validGemPortNum ; i++) {
				if(index < MAX_OMCI_ANI_PORT_NUM){
					if((omci_onu_cap_g.linkMode == OMCI_MODE_XGPON)||(omci_onu_cap_g.linkMode == OMCI_MODE_XGSPON)||(omci_onu_cap_g.linkMode == OMCI_LINK_MODE_NGPON2_10G_10G) \
						||((omci_onu_cap_g.linkMode == OMCI_LINK_MODE_GPON || omci_onu_cap_g.linkMode == OMCI_LINK_MODE_GPON_SYM || omci_onu_cap_g.linkMode == OMCI_LINK_MODE_AUTO) && gemPortList[i]< 4096)) {
						gponGemAssign.gemPort[gponGemAssign.entryNum].id = gemPortList[i] ;
						omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d] type=%d(modify:3, unassign:4),entryNum %d: id=%d, ani=%d\n",
							__FUNCTION__, __LINE__,ifcHandleType,gponGemAssign.entryNum,gemPortList[i],index);
						gponGemAssign.entryNum++ ;
					}
				}
			}

			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d] type=%d(3:modify, 4:unassign) entryNum = %d\n", __FUNCTION__, __LINE__,ifcHandleType,gponGemAssign.entryNum);
			ret = gponmgr_lib_gemport_unassign(&gponGemAssign);

			if(ret != 0) {
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR,"in [%s][%d] ioctl IF_IOS_GEMPORT_UNASSIGN failed! ret=%d\n", __FUNCTION__, __LINE__,ret);
			}
		
			ret = gpon_ani_map_delete(&gponGemAssign);
			if(ret != 0) {
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR,"in [%s][%d] ioctl PONVLAN_IOC_DEL_GPON_ANI_MAP_OPT failed! ret=%d\n", __FUNCTION__, __LINE__,ret);
			}
			if(GPON_HANDLE_PON_IFC_UNASSIGN == ifcHandleType){
				break;
			} // else mean modify, fall through to create

		case GPON_HANDLE_PON_IFC_CREATE:
    		gponGemAssign.entryNum = 0 ;
    		for(i=0 ; i < validGemPortNum ; i++) {
				if(index < MAX_OMCI_ANI_PORT_NUM){
					if((omci_onu_cap_g.linkMode == OMCI_MODE_XGPON)||(omci_onu_cap_g.linkMode == OMCI_MODE_XGSPON)||(omci_onu_cap_g.linkMode == OMCI_LINK_MODE_NGPON2_10G_10G) \
						||((omci_onu_cap_g.linkMode == OMCI_LINK_MODE_GPON || omci_onu_cap_g.linkMode == OMCI_LINK_MODE_GPON_SYM || omci_onu_cap_g.linkMode == OMCI_LINK_MODE_AUTO) && gemPortList[i]< 4096)){
    					gponGemAssign.gemPort[gponGemAssign.entryNum].id = gemPortList[i] ;
    					gponGemAssign.gemPort[gponGemAssign.entryNum].ani = index ;
    					omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d] create,entryNum %d: id=%d, ani=%d\n",
							__FUNCTION__, __LINE__,gponGemAssign.entryNum,gemPortList[i],index);
						gponGemAssign.entryNum++ ;
    				}
    			}
    		}
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d] create, validGemPortNum=%d, entryNum = %d\n",
				__FUNCTION__, __LINE__,validGemPortNum,gponGemAssign.entryNum);
			ret = gponmgr_lib_gemport_assign(&gponGemAssign);
    		if(ret != 0) {
    			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR,"in [%s][%d] ioctl IF_IOS_GEMPORT_ASSIGN failed!\n", __FUNCTION__, __LINE__);
			}else{
                //omci_tcapi_set("XPON_Common","GponBindIfc", "Yes");
                omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"in [%s][%d] ioctl IF_IOS_GEMPORT_ASSIGN success!\n", __FUNCTION__, __LINE__);
			}
			ret = gpon_ani_map_add(&gponGemAssign);
			if(ret != 0) {
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR,"in [%s][%d] ioctl PONVLAN_IOC_ADD_GPON_ANI_MAP_OPT failed! ret=%d\n", __FUNCTION__, __LINE__,ret);
			}
			break;

		case GPON_HANDLE_PON_IFC_DEL:	
			info_ptr = findMBPortInfo(instId);
			gponGemAssign.entryNum = 0 ;
			if((info_ptr != NULL) 
				&& (info_ptr->type == OMCI_MAC_BRIDGE_PORT_WAN_IFC)){
				for(i=0; i<MAX_MAC_BRIDGE_PORT_GEM_PORT_NUM; i++){
					if(info_ptr->gemlist[i][0] == OMCI_VALID_MB_PORT_GEM_PORT){
						gponGemAssign.gemPort[gponGemAssign.entryNum].id = info_ptr->gemlist[i][1] ;
						omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d] delete,entryNum %d, ani=%d\n",
							__FUNCTION__, __LINE__,gponGemAssign.entryNum,index);
						gponGemAssign.entryNum++ ;		
					}
				}
			}
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d] delete entryNum = %d\n", __FUNCTION__, __LINE__,gponGemAssign.entryNum);
			ret = gponmgr_lib_gemport_unassign(&gponGemAssign);
    		if(ret  != 0) {
    			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR,"in [%s][%d] ioctl GPON_HANDLE_PON_IFC_DEL failed!\n", __FUNCTION__, __LINE__);
   		    }
			ret = gpon_ani_map_delete(&gponGemAssign);
			if(ret != 0) {
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR,"in [%s][%d] ioctl PONVLAN_IOC_DEL_GPON_ANI_MAP_OPT failed! ret=%d\n", __FUNCTION__, __LINE__,ret);
			}
			break;
		default:
    		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR,"in [%s][%d] unexpected error!\n", __FUNCTION__, __LINE__);
			ret = -1;
			goto end;
	}	

	ret = 0;
	
end:
	pthread_mutex_unlock(&omciHandlePonIfc);

	return ret;
}


static void getOmciEtherAddr(unsigned char *mac_addr)
{
	char macaddr[32] = {0};
	int i;
	char *macptr = NULL;
	char *macmove = NULL;
	
	char cmd[32]={0};
	char tmpBuf[512]={0};
	char *pValue=NULL;
	FILE * fp=NULL;
	char macInfo[2][18];
	char temp[]="/tmp/test.conf";

	memset(macInfo,0, sizeof(macInfo));	
	sprintf(cmd,"ifconfig eth0 > %s", temp);
	system(cmd);	
	fp=fopen(temp, "r");
	if(fp==NULL){
		return;
	}
	else{
		while (fgets (tmpBuf, sizeof(tmpBuf), fp) != NULL){
			/*krammer add*/
			if((pValue=strstr(tmpBuf,"HWaddr"))){
			       /*tmpBuf format: HWaddr 00:AA:BB:01:23:45*/
				sscanf(pValue,"%s %s", macInfo[0],macInfo[1]);
                        }
		}
	}
	fclose(fp);
	if(strlen(macInfo[1])>0){
		strcpy(macaddr, macInfo[1]);
	}	
	unlink(temp);
	
	macptr = macmove = macaddr;
	
	for(i = 0; i < 6; i++)
	{
		if((macmove = strchr(macptr,':')) == NULL)
			break;
		*macmove = '\0';
		mac_addr[i] = (unsigned char)strtoul(macptr,NULL,16);
		macptr = macmove + 1;
	}
	mac_addr[i] = (unsigned char)strtoul(macptr,NULL,16);
	return;
}

/*******************************************************************************************
**function name
	getGemPortIdFromGemInterTP
**description:
	get gem port id from 9.2.4 GEM interworking termination point or 9.2.5 Multicast GEM interworking termination point
 **retrun :
 	-1:	failure
 	0:	success
**parameter:
  	meClassId :	me class id
  	instId: 		instance id
  	gemPortId:	return gem port id (1~255)
********************************************************************************************/
int getGemPortIdFromGemInterTP(IN uint16_t classId, IN  uint16_t instId, OUT uint16_t *gemPortId){
	int ret = -1;
	uint16_t gemPortInstId = 0;
	omci_me_info_t me_info = {0};
	omci_gem_interwork_tp_ptr gem_interwork_tp_attr = NULL;
	omci_mc_gem_interwork_tp_ptr mc_gem_interwork_tp_ptr = NULL;
	omci_gem_port_ctp_ptr gem_port_ctp_attr = NULL;

	if(gemPortId == NULL){
		ret= -1;
		goto end;
	}
	me_info.class_id = classId;
	me_info.inst_id = instId;
	if(omci_attr_get_all_data_except_table_attr(&me_info) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}
	
	if(classId == OMCI_CLASS_ID_GEM_INTERWORK_TP){
		gem_interwork_tp_attr = (omci_gem_interwork_tp_ptr)me_info.attributes;
		if(NULL == gem_interwork_tp_attr){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->gem_interwork_tp_attr calloc fail\n",__FUNCTION__);
			ret = -1;
			goto end;
		}
		gemPortInstId = gem_interwork_tp_attr->gemPortNetCTPConPtr;
	}
	else if(classId == OMCI_CLASS_ID_MULTICAST_GEM_INTERWORK_TP){
		mc_gem_interwork_tp_ptr = (omci_mc_gem_interwork_tp_ptr)me_info.attributes;
		if(NULL == mc_gem_interwork_tp_ptr){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->gem_interwork_tp_attr calloc fail\n",__FUNCTION__);
			ret = -1;
			goto end;
		}
		gemPortInstId = mc_gem_interwork_tp_ptr->gemPortNetCTPConPtr;
	}

	/*get gem port id form GEM port network CTP ME*/
	me_info.class_id = OMCI_CLASS_ID_GEM_PORT_CTP;
	me_info.inst_id = gemPortInstId;
	if(omci_attr_get_all_data_except_table_attr(&me_info) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}
	gem_port_ctp_attr = (omci_gem_port_ctp_ptr)me_info.attributes;
	if(NULL == gem_port_ctp_attr){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->gem_port_ctp_attr calloc fail\n",__FUNCTION__);
		ret = -1;
		goto end;
	}

	*gemPortId  = gem_port_ctp_attr->portId;
	
	ret = 0;	
end:
	if(ret != 0){
		ret = -1;
	}
	return ret;
}

/*******************************************************************************************
**function name
	getGemPortByMACBridgePortInst
**description:
	according mac bridge port config data instance id, get gem port list
 **retrun :
 	-1:	failure
 	0:	success
**parameter:
	instanceId:	9.3.4 instance id
	gemPort :	gemp port list
  	validGemPortNum :	valid gem port num.
********************************************************************************************/
int getGemPortByMACBridgePortInst(IN uint16_t instanceId, OUT uint16_t * gemPort, OUT uint8_t * validGemPortNum){
	int ret = -1;
	uint8_t tpType = 0;
	uint16_t tpPointer = 0;	
	int i = 0, j = 0; 
	uint8_t currGemPortNum = 0;
	uint8_t findFlag = OMCI_NO_FIND_RULE;
	uint16_t tempGemPortId = 0;
	omci_me_info_t me_info = {0};
	omci_mac_br_port_cfg_ptr mac_br_attr = NULL;
	omci_802_1p_map_service_ptr map_802_1p_attr = NULL;

	if(gemPort == NULL ||validGemPortNum == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d]->parameters is error, fail\r\n",__FUNCTION__,__LINE__);
		goto end;
	}
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
	me_info.class_id = OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA;
	me_info.inst_id = instanceId;
	if(omci_attr_get_all_data_except_table_attr(&me_info) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}
	mac_br_attr = (omci_mac_br_port_cfg_ptr)me_info.attributes;
	if(NULL == mac_br_attr){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]->mac_br_attr calloc fail\n",__FUNCTION__,__LINE__);
		goto end;
	}
			 
	/*get TP type attribute value*/
	tpType = mac_br_attr->tpType;
	
	/*get TP pointer attribute value*/
	tpPointer = mac_br_attr->tpPointer;

	switch(tpType){		
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_3:// get gem port id  from 802.1p ME
			me_info.class_id = OMCI_CLASS_ID_802_1P_MAPPER;
			me_info.inst_id = tpPointer;
			if(omci_attr_get_all_data_except_table_attr(&me_info) != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
				ret = -1;
				goto end;
			}
			map_802_1p_attr = (omci_802_1p_map_service_ptr)me_info.attributes;
			if(NULL == map_802_1p_attr){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->map_802_1p_attr calloc fail\n",__FUNCTION__);
				ret = -1;
				goto end;
			}

			for(i = 0; i<MAX_OMCI_PBIT_NUM; i++){
				/*get interwork TP pointer for P-bit priority i*/
				tpPointer = map_802_1p_attr->tpPointerP[i];
				if(tpPointer == OMCI_DOT1P_INTERWORK_TP_DISCARD){
					omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, " %s->802.1p->tpPointer == 0xff, i=%d\r\n",__FUNCTION__, i);
					continue;
				}
				/*get a gem port id */
				ret = getGemPortIdFromGemInterTP(OMCI_CLASS_ID_GEM_INTERWORK_TP, tpPointer, &tempGemPortId);
				if(ret != 0){
					omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s->802.1p->getGemPortIdFromGemInterTP,tpPointer=0x%02x ,fail\r\n",__FUNCTION__,tpPointer);
					ret = -1;
					goto end;
				}
				/*find gem port in gemPort array*/
				findFlag = OMCI_NO_FIND_RULE;
				for(j = 0; j<currGemPortNum; j++){
					if(*(gemPort+j) == tempGemPortId){
						findFlag = OMCI_FIND_RULE;
						break;
					}	
				}
				/*get new gem port id*/
				if(findFlag == OMCI_FIND_RULE){
					continue;
				}
				*(gemPort+currGemPortNum) = tempGemPortId;
				currGemPortNum++;
				if(currGemPortNum > MAX_MAC_BRIDGE_PORT_GEM_PORT_NUM){
					omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s->gem port num overflow, currGemPortNum = %d, fail\r\n",__FUNCTION__,currGemPortNum);
					ret = -1;
					goto end;
				}
			}
			
			break;
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_5://get gem port id form GEM interworking termination point ME
			/*get a gem port id */
			ret = getGemPortIdFromGemInterTP(OMCI_CLASS_ID_GEM_INTERWORK_TP, tpPointer, &tempGemPortId);
			if(ret != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s->GEM TP->getGemPortIdFromGemInterTP,tpPointer=0x%02x ,fail\r\n",__FUNCTION__,tpPointer);
				ret = -1;
				goto end;
			}
			*gemPort = tempGemPortId;
			currGemPortNum = 1;
			break;
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_6://get gem port id form multicast gem interworking termination point ME
			/*get a gem port id */
			ret = getGemPortIdFromGemInterTP(OMCI_CLASS_ID_MULTICAST_GEM_INTERWORK_TP, tpPointer, &tempGemPortId);
			if(ret != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s->Multicast TP->getGemPortIdFromGemInterTP,tpPointer=0x%02x ,fail\r\n",__FUNCTION__,tpPointer);
				ret = -1;
				goto end;
			}
			*gemPort = tempGemPortId;
			currGemPortNum = 1;
			break;
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_1:
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_4:
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_11:
		default:
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s->tpType=0x%02x\r\n",__FUNCTION__,tpType);
			ret = -1;
			goto end;
	}

/*   This code is unreasonable: when create vlan_tag_filter and type= 802.1 mapping,  
	no gem port find current, because create gem port is after this create vlan_tag_filter, but should return success!
	if(currGemPortNum == 0){// not find
		ret = -1;
		goto end;
	}
*/
	*validGemPortNum = currGemPortNum;
	ret = 0;
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, " %s return ret=%d, validGemPortNum=%d\r\n",__FUNCTION__,ret,*validGemPortNum);
end:
	return ret;
}

/*******************************************************************************************
**function name
	modifyMacBridgePortDeviceId
**description:
	set  device id of mac bridge ANI port
 **retrun :
 	1:	fail
 	0:	success
**parameter:
	instId: 9.3.4 instance id in ANI 
	type: 0:add device id, 1:del device id, 2:modify
********************************************************************************************/
int setMacBridgePortDeviceId(IN uint16_t instId, IN uint8_t type){
	int ret = OMCI_MAC_BRIDGE_PORT_FAIL;
	uint16_t aniPortId = 0;
	int i= 0;
	uint8_t findFlag = OMCI_NO_FIND_RULE;
	uint16_t gemPortList[MAX_MAC_BRIDGE_PORT_GEM_PORT_NUM] = {0};
	uint16_t oldGemPortList[MAX_MAC_BRIDGE_PORT_GEM_PORT_NUM] = {0};
	uint16_t oldValidGemPortNum = 0;
	uint8_t validGemPortNum = 0;
	mb_port_info_ptr mbPortInfo_ptr = NULL;
	mb_port_info_ptr tmpInfo_ptr = NULL;

	pthread_mutex_lock(&omciSetMBPDevId);

	if((type != OMCI_ADD_MAC_BRIDGE_ANI_PORT) 
		&& (type != OMCI_DEL_MAC_BRIDGE_ANI_PORT)
		&& (type != OMCI_MOD_MAC_BRIDGE_ANI_PORT)
		&& (type != OMCI_RECFG_MAC_BRIDGE_ANI_PORT)){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s->type=0x%02x, fail\r\n",__FUNCTION__, type);
		goto end;
	}
	
	if(findOmciAniPortId(instId, &findFlag, &aniPortId) == OMCI_MAC_BRIDGE_PORT_FAIL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, " %s-->findOmciAniPortId, fail\r\n",__FUNCTION__);
		goto end;
	}

	/*calloc memory for storing mac bridge port information*/
 
	mbPortInfo_ptr = (mb_port_info_ptr)calloc(1 , sizeof(mb_port_info_t));
	if(mbPortInfo_ptr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s->calloc failure\r\n",__FUNCTION__);
		goto end;
	}
	memset(mbPortInfo_ptr,0, sizeof(mb_port_info_t));
	
	if((type == OMCI_MOD_MAC_BRIDGE_ANI_PORT)
		|| (type == OMCI_ADD_MAC_BRIDGE_ANI_PORT)
		|| (type == OMCI_RECFG_MAC_BRIDGE_ANI_PORT))
	{
		
		/*get gem port id*/
		if(getGemPortByMACBridgePortInst(instId, gemPortList, &validGemPortNum) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, " %s->getGemPortByMACBridgePortInst,instId=%d, fail\r\n",__FUNCTION__,instId);
		}
		/*set value to mac bridge port information node */
		mbPortInfo_ptr->instId = instId;
		mbPortInfo_ptr->type = OMCI_MAC_BRIDGE_PORT_WAN_IFC;
		mbPortInfo_ptr->reserve = 0;
		for(i=0; i<validGemPortNum; i++){
			mbPortInfo_ptr->gemlist[i][0] = OMCI_VALID_MB_PORT_GEM_PORT;
			mbPortInfo_ptr->gemlist[i][1] = gemPortList[i];
		}

		if(findFlag == OMCI_NO_FIND_RULE){//add
			if(type == OMCI_ADD_MAC_BRIDGE_ANI_PORT){
				if(getFreeOmciAniPortId(&aniPortId) == OMCI_MAC_BRIDGE_PORT_FAIL){
					omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s-->getFreeOmciAniPortId,type=0x%02x, fail\r\n",__FUNCTION__, type);
					goto end;
				}
				/*add mac bridge port information node to list*/
				if(addMBPortInfo(mbPortInfo_ptr) != 0){
					omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s-->addMBPortInfo,9.3.4 instance id=0x%02x, fail\r\n",__FUNCTION__, instId);
					goto end;
				}
				validAniPortFlag[aniPortId][OMCI_ANI_PORT_INST_ID_INDEX] = instId;
				validAniPortFlag[aniPortId][OMCI_ANI_PORT_VALID_INDEX] = OMCI_VALID_MAC_BRIDGE_PORT_FLAG;
				/*create PON interface API*/

				if(handlePonIfc(GPON_HANDLE_PON_IFC_CREATE,aniPortId,gemPortList,validGemPortNum,instId) != 0){
					omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s-->handlePonIfc create,type=0x%02x, fail\r\n",__FUNCTION__, type);
				}
			}
		}
		else{//find and modify
			if(type != OMCI_RECFG_MAC_BRIDGE_ANI_PORT){
				/*unassign gem port */
				tmpInfo_ptr = findMBPortInfo(instId);
				if((tmpInfo_ptr != NULL) 
					&& (tmpInfo_ptr->type == OMCI_MAC_BRIDGE_PORT_WAN_IFC)){
					for(i=0; i<MAX_MAC_BRIDGE_PORT_GEM_PORT_NUM; i++){
						if(tmpInfo_ptr->gemlist[i][0] == OMCI_VALID_MB_PORT_GEM_PORT){
							oldGemPortList[oldValidGemPortNum] = tmpInfo_ptr->gemlist[i][1];
							oldValidGemPortNum++;
						}
					}
				}
				/*  for debug
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  oldValidGemPortNum=%d,aniPortId=%d,instId=%d\r\n ", 
					__FUNCTION__,__LINE__,oldValidGemPortNum,aniPortId,instId);	
				for(j=0; j<oldValidGemPortNum; j++){
					omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  oldGemPortList[%d]=%d\r\n ", 
						__FUNCTION__,__LINE__,j,oldGemPortList[j]); 
				}
				*/
				if(oldValidGemPortNum > 0){
					if(handlePonIfc(GPON_HANDLE_PON_IFC_UNASSIGN,aniPortId,oldGemPortList,oldValidGemPortNum,instId) != 0){
						omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s-->handlePonIfc unassign gemport,type=0x%02x, fail\r\n",__FUNCTION__, type);
					}
				}
			}
			
			/*modify mac bridge port information node to list*/
			if(addMBPortInfo(mbPortInfo_ptr) != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s-->addMBPortInfo(modify),9.3.4 instance id=0x%02x, fail\r\n",__FUNCTION__, instId);
				goto end;
			}
			if(type != OMCI_RECFG_MAC_BRIDGE_ANI_PORT){
			/*modify PON interface API*/			
				if(handlePonIfc(GPON_HANDLE_PON_IFC_CREATE,aniPortId,gemPortList,validGemPortNum,instId) != 0){
					omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s-->handlePonIfc modify,type=0x%02x, fail\r\n",__FUNCTION__, type);
				}
			}
			else if(handlePonIfc(GPON_HANDLE_PON_IFC_MODIFY,aniPortId,gemPortList,validGemPortNum,instId) != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s-->handlePonIfc modify,type=0x%02x, fail\r\n",__FUNCTION__, type);
			}
		}
	}
	else if(type == OMCI_DEL_MAC_BRIDGE_ANI_PORT){
		/*delete PON interface API*/
		if(findFlag == OMCI_FIND_RULE){
			if(validAniPortFlag[aniPortId][OMCI_ANI_PORT_VALID_INDEX] == OMCI_VALID_MAC_BRIDGE_PORT_FLAG){
				if(handlePonIfc(GPON_HANDLE_PON_IFC_DEL,aniPortId,NULL,0,instId) != 0){
					omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s-->handlePonIfc del,type=0x%02x, fail\r\n",__FUNCTION__, type);
				}
				/*modify mac bridge port information node to list*/
				if(delMBPortInfo(instId) != 0){
					omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s-->delMBPortInfo,9.3.4 instance id=0x%02x, fail\r\n",__FUNCTION__, instId);
				}
			}
			validAniPortFlag[aniPortId][OMCI_ANI_PORT_INST_ID_INDEX] = 0;
			validAniPortFlag[aniPortId][OMCI_ANI_PORT_VALID_INDEX] = OMCI_INVALID_MAC_BRIDGE_PORT_FLAG;
		}
	}
	ret = OMCI_MAC_BRIDGE_PORT_SUCCESS;
end:
	pthread_mutex_unlock(&omciSetMBPDevId);
	if(mbPortInfo_ptr != NULL){
		free(mbPortInfo_ptr);
		mbPortInfo_ptr = NULL;
	}
	return ret;
}

/*******************************************************************************************
**function name
	omciRecfgIfc
**description:
	reset mapping rule between ANI interface and gemport.
 **retrun :
 	-1:	fail
 	0:	success
**parameter:
	none
********************************************************************************************/
int recfgTimerId = 0;

int omciRecfgIfcTimeOut(void){
	int ret = OMCI_MAC_BRIDGE_PORT_FAIL;
	int i = 0;
	pthread_mutex_lock(&omciGetAllData);
	recfgTimerId = 0;
	for(i = 0; i<MAX_OMCI_ANI_PORT_NUM; i++){
		if(validAniPortFlag[i][OMCI_ANI_PORT_VALID_INDEX] == OMCI_VALID_MAC_BRIDGE_PORT_FLAG){
			if(setMacBridgePortDeviceId(validAniPortFlag[i][OMCI_ANI_PORT_INST_ID_INDEX], OMCI_RECFG_MAC_BRIDGE_ANI_PORT) == OMCI_MAC_BRIDGE_PORT_FAIL){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s->validAniPortFlag[%d][0]=0x%02x, fail[%d]\n",__FUNCTION__,i, validAniPortFlag[i][OMCI_ANI_PORT_INST_ID_INDEX], __LINE__);
			}
		}

	}
	pthread_mutex_unlock(&omciGetAllData);
	ret = OMCI_MAC_BRIDGE_PORT_SUCCESS;
	return ret;	
}


int omciRecfgIfc(void)
{
    /* use time function ; because trap handler may 
    block OMCI RX handler while doing this action */
    omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d] start timer for omciRecfgIfc\r\n",__FUNCTION__,__LINE__);
	if(recfgTimerId > 0){
		timerStopS(recfgTimerId);
		recfgTimerId = 0;
	}
	recfgTimerId = timerStartS(500 , (TimerCallback)omciRecfgIfcTimeOut, NULL);
    if (recfgTimerId <= 0 )
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "omci delay  omciRecfgIfc fail!");
        return -1;
    }
    return 0;
}

/*******************************************************************************************
**function name
	addGemPortRuleByMbPortUNI
**description:
	add gem port rule, according to the 9.3.4 point to the PPTP UNI or IP host config data for CUC
 **retrun :
 	-1:	failure
 	0:	success
**parameter:
  	instId :	9.3.4 UNI instance id
********************************************************************************************/
int addGemPortRuleByMbPortUNI(uint16_t instId){
	int ret = -1;
	uint8_t tpType = 0;
	uint16_t mbpInstId = 0;//9.3.1 mac bridge service profile instance id
	uint16_t tempMbpInstId = 0;
	uint8_t tempTpType = 0;
	uint16_t tempTpPointer = 0;
	uint16_t tempInstId = 0;
	uint8_t userPort = 0;
	uint32_t classIdInstId = 0;
	uint32_t meIdArr[MAX_GEMPORT_VALID_MEID_NUM] = {0};
	uint8_t validNum  = 0;
	uint16_t inst_id_array[MAX_INST_COUNT]={0};
	uint16_t tp_ptr_val = 0;
	int inst_count = 0, i = 0;
	omci_me_info_t me_info = {0};
	omci_mac_br_port_cfg_ptr mac_br_attr = NULL;

	/*1.get some information from current instance */	
	me_info.class_id = OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA;
	me_info.inst_id = instId;
	if(omci_attr_get_all_data_except_table_attr(&me_info) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}
	
	mac_br_attr = (omci_mac_br_port_cfg_ptr)me_info.attributes;
	if(NULL == mac_br_attr){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->mac_br_attr calloc fail\n",__FUNCTION__);
		ret = -1;
		goto end;
	}
	/*1.1 get tp type attribute value*/
	tpType = mac_br_attr->tpType;

	/*1.2 get tp pointer attribute value*/
	tp_ptr_val = mac_br_attr->tpPointer;

	/*1.3 get user port and classIdInstId from current instance*/
	switch(tpType){
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_1:
			userPort = getPortIdxByInstId(tp_ptr_val);
			break;
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_11:
			userPort = 0;
			break;
#ifdef TCSUPPORT_PON_IP_HOST
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_4:
			userPort = (uint8_t)(tp_ptr_val & 0xFF) + IP_HOST_CONFIG_PORT_BASIC;
			break;	
#endif
		default :
			ret = 0;
			goto  end;
	}

	classIdInstId = (OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA << 16);
	classIdInstId |= instId;
	
	/*1.4 get mac bridge id(9.3.1) pointer attribute value*/
	mbpInstId = mac_br_attr->bridgeIDPointer;

	
	/*3.traversal all 9.3.4 instance*/

	if(omci_lib_get_inst_count_by_classid(OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA, &inst_count) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]omci_lib_get_inst_count_by_classid failed.\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
	}
	
	if(omci_lib_get_inst_list_by_classid(OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA, inst_id_array, inst_count) == -1){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]omci_lib_get_inst_list_by_classid failed.\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
	}

	for(i = 0; i < inst_count; i++){
		/*3.1 get 9.3.4 instance id*/
		me_info.class_id = OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA;
		me_info.inst_id = inst_id_array[i];
		if(omci_attr_get_all_data_except_table_attr(&me_info) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
			continue;
		}
		
		mac_br_attr = (omci_mac_br_port_cfg_ptr)me_info.attributes;
		if(NULL == mac_br_attr){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->mac_br_attr calloc fail\n",__FUNCTION__);
			continue;
		}
		
		/*3.2 get mac bridge id(9.3.1) pointer attribute value*/
		tempMbpInstId = mac_br_attr->bridgeIDPointer;
		
		/*3.3 jump different mac bridge with current mac bridge */
		if(tempMbpInstId != mbpInstId){
			continue;
		}
	
		/*3.4 get 9.3.4 tp type attribute value*/
		tempTpType= mac_br_attr->tpType;

		/*3.5 get 9.3.4 tp pointer attribute value*/
		tempTpPointer= mac_br_attr->tpPointer;
	
		/*3.6 add gem port rule by user port */
		tempInstId = mac_br_attr->meId;
		switch(tempTpType){
			case OMCI_MAC_BRIDGE_PORT_TP_TYPE_3:
			case OMCI_MAC_BRIDGE_PORT_TP_TYPE_5:
//			case OMCI_MAC_BRIDGE_PORT_TP_TYPE_6: //multicast gemport should not be included 
				meIdArr[0] = (OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA << 16);
				meIdArr[0] |=  tempInstId;
				meIdArr[1] = (OMCI_CLASS_ID_VLAN_TAG_FILTER_DATA << 16);
				meIdArr[1] |=  tempInstId;
				validNum = 2;
				if(tempTpType == OMCI_MAC_BRIDGE_PORT_TP_TYPE_3){
					meIdArr[2] = (OMCI_CLASS_ID_802_1P_MAPPER << 16);
					meIdArr[2] |=  tempTpPointer;
					validNum = 3;
				}
				
				if(addOmciGemPortMappingRuleByUni(userPort, classIdInstId, meIdArr, validNum) != 0){
					omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n %s-> addOmciGemPortMappingRuleByUni, instid=0x%02x,fail",__FUNCTION__,tempInstId);
				}
				break;
			default:
				break;				
		}
	}
	ret = 0;
end:
	return ret;
}
	
int updateGemPortRuleByMbPortUNIandANI(uint16_t instId,uint16_t aniInstID){
	int ret = -1;
	uint8_t tpType = 0;
	uint16_t mbpInstId = 0;//9.3.1 mac bridge service profile instance id
	uint16_t tempMbpInstId = 0;
	uint8_t tempTpType = 0;
	uint16_t tempInstId = 0;
	uint8_t userPort = 0;
	uint32_t classIdInstId = 0;
	uint32_t meIdArr[MAX_GEMPORT_VALID_MEID_NUM] = {0};
	uint8_t validNum  = 0;
	uint16_t tp_ptr_val = 0;
	omci_me_info_t me_info = {0};
	omci_mac_br_port_cfg_ptr mac_br_attr = NULL;

	/*1.get some information from current instance */	
	me_info.class_id = OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA;
	me_info.inst_id = instId;
	if(omci_attr_get_all_data_except_table_attr(&me_info) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}
	
	mac_br_attr = (omci_mac_br_port_cfg_ptr)me_info.attributes;
	if(NULL == mac_br_attr){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->mac_br_attr calloc fail\n",__FUNCTION__);
		ret = -1;
		goto end;
	}
	/*1.1 get tp type attribute value*/
	tpType = mac_br_attr->tpType;

	/*1.2 get tp pointer attribute value*/
	tp_ptr_val = mac_br_attr->tpPointer;

	/*1.3 get user port and classIdInstId from current instance*/
	switch(tpType){
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_1:
			userPort = getPortIdxByInstId(tp_ptr_val);
			break;
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_11:
			userPort = 0;
			break;
#ifdef TCSUPPORT_PON_IP_HOST
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_4:
			userPort = (uint8_t)(tp_ptr_val & 0xFF) + IP_HOST_CONFIG_PORT_BASIC;
			break;	
#endif
		default :
			ret = 0;
			goto  end;
	}

	classIdInstId = (OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA << 16);
	classIdInstId |= instId;
	
	/*1.4 get mac bridge id(9.3.1) pointer attribute value*/
	mbpInstId = mac_br_attr->bridgeIDPointer;

	/*3.1 get 9.3.4 instance id*/
	me_info.class_id = OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA;
	me_info.inst_id = aniInstID;
	if(omci_attr_get_all_data_except_table_attr(&me_info) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}
	
	mac_br_attr = (omci_mac_br_port_cfg_ptr)me_info.attributes;
	if(NULL == mac_br_attr){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->mac_br_attr calloc fail\n",__FUNCTION__);
		ret = -1;
		goto end;
	}
	
	/*3.2 get mac bridge id(9.3.1) pointer attribute value*/
	tempMbpInstId = mac_br_attr->bridgeIDPointer;
	
	/*3.3 jump different mac bridge with current mac bridge */
	if(tempMbpInstId != mbpInstId){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->mac_br_attrinst not match\n",__FUNCTION__);
		ret = -1;
		goto  end;
	}

	/*3.4 get 9.3.4 tp type attribute value*/
	tempTpType= mac_br_attr->tpType;

	if(tempTpType == OMCI_MAC_BRIDGE_PORT_TP_TYPE_3){ //802.19 not handle,cause function addGemPortMappingRuleByAniPort didn't handle
		ret = 0;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]->don't include 802.1p\n",__FUNCTION__,__LINE__);
		goto  end;
	}

	/*3.6 add gem port rule by user port */
	tempInstId = mac_br_attr->meId;
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s->mac_br_attr user port is %d,classIdInstId is %d,tp type is %d\n",__FUNCTION__,userPort,classIdInstId,tempTpType);
	switch(tempTpType){
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_5:
			meIdArr[0] = (OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA << 16);
			meIdArr[0] |=  tempInstId;
			meIdArr[1] = (OMCI_CLASS_ID_VLAN_TAG_FILTER_DATA << 16);
			meIdArr[1] |=  tempInstId;
			validNum = 2;
			if(addOmciGemPortMappingRuleByUni(userPort, classIdInstId, meIdArr, validNum) != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n %s-> addOmciGemPortMappingRuleByUni, instid=0x%02x,fail",__FUNCTION__,tempInstId);
				ret = -1;
				goto end;
			}
			break;
		default:
			break;				
	}

	ret = 0;
end:
	return ret;
}

	
/*******************************************************************************************
**function name
	updateGemMappingRuleByMbPortUNI
**description:
	update gemport rule, accroding the dot1p or vlan filter changed.
 **retrun :
 	-1:	failure
 	0:	success
**parameter:
  	mapType :	1:according to the vlan filter, 2 according to  the dot 1p
  	instId: dot1p(9.3.10)  or vlan filter(9.3.11) ME instance id
********************************************************************************************/
int updateGemMappingRuleByMbPortUNI(uint8_t mapType, uint16_t instId){
	int ret = 0;
	uint16_t mbpInstId = 0;//9.3.1 mac bridge service profile instance id
	uint16_t tempMbpInstId = 0;
	uint8_t tempTpType = 0;
	uint16_t tempTpPointer = 0;
	uint16_t tempInstId = 0;
	uint32_t classIdInstId = 0;
	uint8_t findMb = OMCI_NO_FIND_RULE;
	uint16_t delMatchFlag = 0;
	omciGemPortMapping_ptr mapRule_ptr = NULL;
	uint16_t inst_id_array[MAX_INST_COUNT]={0};
	int inst_count = 0, i = 0;
	omci_me_info_t me_info = {0};
	omci_mac_br_port_cfg_ptr mac_br_attr = NULL;

	/*1.init*/
	if((mapType != OMCI_UPDATE_UNI_MAPPING_BY_VLAN_FILTER_ME)
		&&(mapType != OMCI_UPDATE_UNI_MAPPING_BY_DOT1P_ME)){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s->mapType=%d, fail\n",__FUNCTION__,mapType);
		ret = -1;
		goto end;
	}
	/*malloc and set value for new port mapping*/		
	mapRule_ptr = (omciGemPortMapping_ptr)calloc(1 , sizeof(omciGemPortMapping_t));
	if(mapRule_ptr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s->calloc newRule_ptr  fail\n",__FUNCTION__);
		ret = -1;
		goto end;
	}
	
    /*get ME information*/
	if(omci_lib_get_inst_count_by_classid(OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA, &inst_count) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]omci_lib_get_inst_count_by_classid failed.\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
	}
	
	if(omci_lib_get_inst_list_by_classid(OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA, inst_id_array, inst_count) == -1){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]omci_lib_get_inst_list_by_classid failed.\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
	}

	/*2.find current mac bridge service profile*/
	findMb = OMCI_NO_FIND_RULE;
	for(i = 0; i < inst_count; i++){
		/*2.1 get 9.3.4 instance id*/
		me_info.class_id = OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA;
		me_info.inst_id = inst_id_array[i];
		if(omci_attr_get_all_data_except_table_attr(&me_info) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
			continue;
		}
		
		mac_br_attr = (omci_mac_br_port_cfg_ptr)me_info.attributes;
		if(NULL == mac_br_attr){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->mac_br_attr calloc fail\n",__FUNCTION__);
			continue;
		}
		/* get mac bridge id(9.3.1) pointer attribute value*/
		mbpInstId = mac_br_attr->bridgeIDPointer;

		tempInstId = mac_br_attr->meId;

		/*2.3 get 9.3.4 tp type attribute value*/
		tempTpType= mac_br_attr->tpType;

		/*2.4 get 9.3.4 tp pointer attribute value*/
		tempTpPointer=  mac_br_attr->tpPointer;
	
		if((OMCI_UPDATE_UNI_MAPPING_BY_VLAN_FILTER_ME == mapType)
			&&(tempInstId == instId)//ANI side
			&& ((tempTpType == OMCI_MAC_BRIDGE_PORT_TP_TYPE_3)
				|| (tempTpType == OMCI_MAC_BRIDGE_PORT_TP_TYPE_5)
				|| (tempTpType == OMCI_MAC_BRIDGE_PORT_TP_TYPE_6))){
			findMb = OMCI_FIND_RULE;
		}
		else if((OMCI_UPDATE_UNI_MAPPING_BY_DOT1P_ME == mapType)
			&&(tempTpType == OMCI_MAC_BRIDGE_PORT_TP_TYPE_3)
			&& (tempTpPointer == instId)){
			findMb = OMCI_FIND_RULE;
		}

		if(findMb == OMCI_FIND_RULE)
			break;
	}
	
	if(findMb == OMCI_NO_FIND_RULE){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d] findMb == OMCI_NO_FIND_RULE \n",__FUNCTION__,__LINE__);
		goto end;
	}
	
	/*3.delete old gemport rule and add new rule by user port*/
	delMatchFlag = OMCI_GEMPORT_MAPPING_CLASSID_INSTID;
	for(i = 0; i < inst_count; i++){
		/*3.1 get 9.3.4 instance id*/
		me_info.class_id = OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA;
		me_info.inst_id = inst_id_array[i];
		if(omci_attr_get_all_data_except_table_attr(&me_info) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
			ret = -1;
			goto end;
		}
		
		mac_br_attr = (omci_mac_br_port_cfg_ptr)me_info.attributes;
		if(NULL == mac_br_attr){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->mac_br_attr calloc fail\n",__FUNCTION__);
			ret = -1;
			goto end;
		}
		
		/*3.2 get mac bridge id(9.3.1) pointer attribute value*/
		tempMbpInstId = mac_br_attr->bridgeIDPointer;
		if(mbpInstId != tempMbpInstId){
			continue;
		}
		/*3.3 get 9.3.4 tp type attribute value and find UNI instance*/
		tempTpType= mac_br_attr->tpType;
		if(tempTpType != OMCI_MAC_BRIDGE_PORT_TP_TYPE_1 && tempTpType != OMCI_MAC_BRIDGE_PORT_TP_TYPE_11
#ifdef TCSUPPORT_PON_IP_HOST
			&& tempTpType != OMCI_MAC_BRIDGE_PORT_TP_TYPE_4	
#endif
		){
			continue;
		}

		tempInstId = me_info.inst_id;

		/*3.4 get ME id(class id +instance id)*/
		classIdInstId = (OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA<<16);
		classIdInstId |= tempInstId;
		mapRule_ptr->classIdInstId = classIdInstId;
		/*3.5 delete old gemport rule by user port*/
		if(delOmciGemPortMappingRuleByMatchFlag(delMatchFlag, mapRule_ptr) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s->delOmciGemPortMappingRuleByMatchFlag, fail\r\n",__FUNCTION__);
		}
		/*3.6 add new gemport rule by user port*/
		if(addGemPortRuleByMbPortUNI(tempInstId) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s->addGemPortRuleByMbPortUNI, fail\r\n",__FUNCTION__);
		}
	}

	ret = 0;
end:
	if(mapRule_ptr != NULL){
		free(mapRule_ptr);
		mapRule_ptr = NULL;
	}
	return ret;
}

int updateGemMappingRuleByMbPortANI(uint16_t instId){
	int ret = 0;
	uint8_t userPort = 0;
	uint16_t mbpInstId = 0;//9.3.1 mac bridge service profile instance id
	uint16_t tempMbpInstId = 0;
	uint8_t tempTpType = 0;
	uint16_t tempTpPointer = 0;
	uint16_t tempInstId = 0;
	uint32_t classIdInstId = 0;
	//uint16_t delMatchFlag = 0;
	uint32_t meIdArr[MAX_GEMPORT_VALID_MEID_NUM] = {0};
	uint8_t validNum  = 0;
	omciGemPortMapping_ptr mapRule_ptr = NULL;
	uint16_t inst_id_array[MAX_INST_COUNT]={0};
	int inst_count = 0, i = 0;
	int continue_flag = 0;
	omci_me_info_t me_info = {0};
	omci_mac_br_port_cfg_ptr mac_br_attr = NULL;
	omci_802_1p_map_service_ptr dot1p_map_attr = NULL;

	/*1.init*/
	/*malloc and set value for new port mapping*/		
	mapRule_ptr = (omciGemPortMapping_ptr)calloc(1 , sizeof(omciGemPortMapping_t));
	if(mapRule_ptr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s->calloc newRule_ptr  fail\n",__FUNCTION__);
		ret = -1;
		goto end;
	}
	
    /*get ME information*/
	/*2.find current mac bridge service profile*/
	me_info.class_id = OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA;
	me_info.inst_id = instId;
	if(omci_attr_get_all_data_except_table_attr(&me_info) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}

	mac_br_attr = (omci_mac_br_port_cfg_ptr)me_info.attributes;
	if(NULL == mac_br_attr){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->mac_br_attr calloc fail\n",__FUNCTION__);
		ret = -1;
		goto end;
	}
	/*2.1 get mac bridge id(9.3.1) pointer attribute value*/
	mbpInstId = mac_br_attr->bridgeIDPointer;

	/*2.1 get mac bridge id(9.3.1) meid value*/
	tempInstId = mac_br_attr->meId;

	/*2.3 get 9.3.4 tp type attribute value*/
	tempTpType= mac_br_attr->tpType;

	/*2.4 get 9.3.4 tp pointer attribute value*/
	tempTpPointer=  mac_br_attr->tpPointer;

	/*3. get 802.1p mapper information*/
	me_info.class_id = OMCI_CLASS_ID_802_1P_MAPPER;
	me_info.inst_id = tempTpPointer;
	if(omci_attr_get_all_data_except_table_attr(&me_info) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]802.1p mapper is not create yet, does not need to update.\n",__FUNCTION__,__LINE__);
		ret = 0;
		goto end;
	}
	
	dot1p_map_attr = (omci_802_1p_map_service_ptr)me_info.attributes;
	if(NULL == dot1p_map_attr){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->dot1p_map_attr calloc fail\n",__FUNCTION__);
		ret = -1;
		goto end;
	}
	
	for(i = 0; i < 8; i++) {
		if(dot1p_map_attr->tpPointerP[i] != OMCI_DOT1P_INTERWORK_TP_DISCARD)
			break;
		if(i == 7) {
			ret = 0;
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]802.1p mapper is not set yet, does not need to update.\n",__FUNCTION__,__LINE__);
			goto end;
		}	
	}
	
	/*get ME information*/
	if(omci_lib_get_inst_count_by_classid(OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA, &inst_count) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]omci_lib_get_inst_count_by_classid failed.\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
	}
	
	if(omci_lib_get_inst_list_by_classid(OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA, inst_id_array, inst_count) == -1){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]omci_lib_get_inst_list_by_classid failed.\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
	}

	/*4. add GEM port mapping rule*/
	for(i = 0; i < inst_count; i++){
		/*4.1 get 9.3.4 instance id*/
		me_info.class_id = OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA;
		me_info.inst_id = inst_id_array[i];
		if(omci_attr_get_all_data_except_table_attr(&me_info) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
			ret = -1;
			goto end;
		}
		
		mac_br_attr = (omci_mac_br_port_cfg_ptr)me_info.attributes;
		if(NULL == mac_br_attr){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->mac_br_attr calloc fail\n",__FUNCTION__);
			ret = -1;
			goto end;
		}
		
		/*4.2 get mac bridge id(9.3.1) pointer attribute value*/
		tempMbpInstId = mac_br_attr->bridgeIDPointer;
		if(mbpInstId != tempMbpInstId){
			continue;
		}

		/*4.3 get userPort*/
		continue_flag = 0;
		switch(mac_br_attr->tpType){
			case OMCI_MAC_BRIDGE_PORT_TP_TYPE_1:
				userPort = getPortIdxByInstId(mac_br_attr->tpPointer);
				break;
			case OMCI_MAC_BRIDGE_PORT_TP_TYPE_11:
				userPort = 0;
				break;
#ifdef TCSUPPORT_PON_IP_HOST
			case OMCI_MAC_BRIDGE_PORT_TP_TYPE_4:
				userPort = (uint8_t)(mac_br_attr->tpPointer & 0xFF) + IP_HOST_CONFIG_PORT_BASIC;
				break;	
#endif
			default :
				continue_flag = 1;
				break;
		}
		if(continue_flag == 1) {
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, " %s->tpTypenot matched, continue\n",__FUNCTION__);
			continue;
		}
		tempInstId = instId;

		/*4.4 get ME id(class id +instance id)*/
		classIdInstId = (OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA<<16);
		classIdInstId |= tempInstId;
		mapRule_ptr->classIdInstId = classIdInstId;

		switch(tempTpType){
			case OMCI_MAC_BRIDGE_PORT_TP_TYPE_3:
			case OMCI_MAC_BRIDGE_PORT_TP_TYPE_5:
//			case OMCI_MAC_BRIDGE_PORT_TP_TYPE_6: //multicast gemport should not be included 
				meIdArr[0] = (OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA << 16);
				meIdArr[0] |=  tempInstId;
				meIdArr[1] = (OMCI_CLASS_ID_VLAN_TAG_FILTER_DATA << 16);
				meIdArr[1] |=  tempInstId;
				validNum = 2;
				if(tempTpType == OMCI_MAC_BRIDGE_PORT_TP_TYPE_3){
					meIdArr[2] = (OMCI_CLASS_ID_802_1P_MAPPER << 16);
					meIdArr[2] |=  tempTpPointer;
					validNum = 3;
				}
				
				if(addOmciGemPortMappingRuleByUni(userPort, classIdInstId, meIdArr, validNum) != 0){
					omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n %s-> addOmciGemPortMappingRuleByUni, instid=0x%02x,fail",__FUNCTION__,tempInstId);
				}
				break;
			default:
				break;				
		}
	}

	ret = 0;
end:
	if(mapRule_ptr != NULL){
		free(mapRule_ptr);
		mapRule_ptr = NULL;
	}
	return ret;
}

int getPortFromMacBridgeSkipUNIFilterRuleByInstId(OUT uint8_t * skip_filter_flag, IN uint16_t instId)
{  
    int ret = -1;
    uint8_t type = 0;
	omci_me_info_t me_info = {0};
	omci_mac_br_port_cfg_ptr mac_br_attr = NULL;
    
    if(NULL == skip_filter_flag)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s->is_veip_port == NULL, fail\n",__FUNCTION__);
        goto end;
    }

	//2--hgu modes
    /*SFU mode don't need filter pptp ether uni port vlan filter rule*/
	if(SFU == omci_info_g.onuType)
    {
        *skip_filter_flag = 0;
        ret = 0;
        goto end;
    } 
	me_info.class_id = OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA;
	me_info.inst_id = instId;
	if(omci_attr_get_all_data_except_table_attr(&me_info) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}
	mac_br_attr = (omci_mac_br_port_cfg_ptr)me_info.attributes;
	if(NULL == mac_br_attr){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->mac_br_attr calloc fail\n",__FUNCTION__);
		goto end;
	}
	type = mac_br_attr->tpType;
    switch(type)
    {
        case OMCI_MAC_BRIDGE_PORT_TP_TYPE_1:
        {
            *skip_filter_flag = 1;
            break;
        }
        default :
        {
            *skip_filter_flag = 0;
            break;
        }
    }
    
    ret = 0;
end:
    return ret;
}

int getPortFromMacBridgeByInstId(OUT uint8_t *portId, OUT uint8_t * ifaceType, IN uint16_t instId){
	int ret = -1;
	uint8_t port = 0;//UNI/ANI port id	
	int type = 0; // 0:UNI interface, 1:ANI interface
	uint8_t ifcType = 0;

	if(portId == NULL ||ifaceType == NULL ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->parameter is error, failure\n",__FUNCTION__);
		ret = -1;
		goto end;		
	}	

	/*get interface type*/
	type = getMacBridgePortInstType(instId, &ifcType);
	/*only support getting bridge table information in UNI or ANI port*/
	if(type == OMCI_MAC_BRIDGE_PORT_LAN_IFC){//UNI port
		/*get lan  portid*/
		ret = getMacBridgeLanPortId(instId, &port);
		if(ret != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s->getMacBridgeLanPortId failure",__FUNCTION__);
			ret = -1;
			goto end;
		}
	}else if(type == OMCI_MAC_BRIDGE_PORT_WAN_IFC){//ANI port
		/*get Wan  portid*/
		ret = getMacBridgeWanPortId(instId, &port);
		if(ret != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s->getMacBridgeWanPortId failure",__FUNCTION__);
			ret = -1;
			goto end;
		}
	}else{//no UNI/ANI port 
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s->type =%d failure",__FUNCTION__,type);
		ret = -1;
		goto end;
	}

	*portId = port;
	*ifaceType = type;
	ret = 0;
	
end:
	return ret;
}

/*******************************************************************************************
**function name
	getMacBridgePortInstType
**description:
	get interface type  from mac bridge port configuration data
 **retrun :
 	0:	lan interface type
 	1:	wan interface type
 	-1:	failure
**parameter:
  	instId: instance id in mac bridge port configuration data ME.
  	ifcType: 1: WAN multicast tp, 2: wan gem tp, 3: wan dot1p.
********************************************************************************************/
int getMacBridgePortInstType(uint16_t instId, uint8_t * ifcType)
{
	omci_me_info_t me_info = {0};
	omci_mac_br_port_cfg_ptr mac_br_attr = NULL;
	uint8_t type = 0;
	int instType = -1;

	if(ifcType == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->ifcType == NULL, fail\n",__FUNCTION__);
		goto end;
	}
	me_info.class_id = OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA;
	me_info.inst_id = instId;
	if(omci_attr_get_all_data_except_table_attr(&me_info) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
		goto end;
	}
	mac_br_attr = (omci_mac_br_port_cfg_ptr)me_info.attributes;
	if(NULL == mac_br_attr){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->mac_br_attr calloc fail\n",__FUNCTION__);
		goto end;
	}
	type = mac_br_attr->tpType;
	
	switch(type){
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_1:
			*ifcType = OMCI_MAC_BRIDGE_PORT_PPTP_UNI;
			instType = OMCI_MAC_BRIDGE_PORT_LAN_IFC;
			break;
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_4:
#ifdef TCSUPPORT_PON_IP_HOST
			*ifcType = OMCI_MAC_BRIDGE_PORT_IP_CONFIG_HOST;
			instType = OMCI_MAC_BRIDGE_PORT_LAN_IFC;
			break;
#endif
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_11:
            *ifcType = OMCI_MAC_BRIDGE_PORT_VEIP;
            instType = OMCI_MAC_BRIDGE_PORT_LAN_IFC;
			break;
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_3:
			*ifcType = OMCI_MAC_BRIDGE_PORT_DOT1P;
			instType = OMCI_MAC_BRIDGE_PORT_WAN_IFC;
			break;
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_5:
			*ifcType = OMCI_MAC_BRIDGE_PORT_GEM_TP;
			instType = OMCI_MAC_BRIDGE_PORT_WAN_IFC;
			break;
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_6:
			*ifcType = OMCI_MAC_BRIDGE_PORT_MULTICAST_TP;
			instType = OMCI_MAC_BRIDGE_PORT_WAN_IFC;
			break;
		case 2:
		case 7:
		case 8:
		case 9:
		case 10:
		case 12:
		default:
			break;
	}
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s->ifcType=0x%0x\n",__FUNCTION__,*ifcType);
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s->instType=0x%0x\n",__FUNCTION__,instType);
	return instType;
}

/*******************************************************************************************
**function name
	getMacBridgeLanPortId
**description:
	get lan port id from 9.3.4 mac bridge port configuration data
 **retrun :
 	0:	success
 	-1:	failure
**parameter:
  	instId: instance id in 9.3.4 mac bridge port configuration data ME.
  	lanPortId: lan port id (0~3)
********************************************************************************************/
int getMacBridgeLanPortId(uint16_t instId, uint8_t *lanPortId)
{
	omci_me_info_t me_info = {0};
	omci_mac_br_port_cfg_ptr mac_br_attr = NULL;
	uint8_t tp_type = 0;
	uint16_t tp_ptr_val = 0;
	uint8_t portId = 0;
	int ret = -1;

	if(NULL == lanPortId){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->lanPortId == NULL, fail\n",__FUNCTION__);
		ret  = -1;
		goto end;
	}
	me_info.class_id = OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA;
	me_info.inst_id = instId;
	if(omci_attr_get_all_data_except_table_attr(&me_info) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}
	mac_br_attr = (omci_mac_br_port_cfg_ptr)me_info.attributes;
	if(NULL == mac_br_attr){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->mac_br_attr calloc fail\n",__FUNCTION__);
		goto end;
	}
	
	/*find tp type = Physical path termination point Ethernet UNI*/
	tp_type = mac_br_attr->tpType;

	/*get lan port id from TP pointer attribute*/
	tp_ptr_val = mac_br_attr->tpPointer;

	switch(tp_type){
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_1://pptp UNI
			portId = getPortIdxByInstId(tp_ptr_val);
			if(portId > MAX_ETH_PORT_NUM){
				ret = -1;
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n getMacBridgeLanPortId fail, portId=%d", portId);
				goto end;
			}			
			*lanPortId = portId;
			ret = 0;
			break;
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_4://ip host config data
#ifdef TCSUPPORT_PON_IP_HOST
			portId = (uint8_t)(tp_ptr_val & 0xFF);	//Using low byte
			*lanPortId = portId + IP_HOST_CONFIG_PORT_BASIC;
			ret = 0;
			break;
#endif
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_11://virtual ethernet interface point
			*lanPortId = 0;
			ret = 0;
			break;
		default:
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n getMacBridgeLanPortId->TP type isn't LAN port");
			ret = -1;
			break;
	}
	
end:
	return ret;	
}


/*******************************************************************************************
**function name
	getMacBridgeWanPortId
**description:
	get wan port id from mac bridge port configuration data
 **retrun :
 	0:	success
 	-1:	failure
**parameter:
  	instId: instance id in mac bridge port configuration data ME.
  	wanPortId: wan port id (0~31)
********************************************************************************************/
int getMacBridgeWanPortId(uint16_t instId, uint8_t *wanPortId)
{
	uint16_t portId = 0;
	uint8_t findFlag = OMCI_NO_FIND_RULE;

	if(findOmciAniPortId(instId, &findFlag, &portId) == OMCI_MAC_BRIDGE_PORT_FAIL){
		return -1;	
	}
	if(findFlag == OMCI_FIND_RULE)
		*wanPortId = (uint8_t)portId;

	return 0;	
}


/*******************************************************************************************
**function name
    delGemPortMappingRuleByMbp
**description:
    delete gem port mapping rule by mac bridge port
 **retrun :
    -1: failure
    0:  success
**parameter:
    instId: 9.3.4 instance id
********************************************************************************************/
int delGemPortMappingRuleByMbp(IN uint16_t instId){
    int ret = -1;
    uint16_t delMatchFlag = 0;
    omciGemPortMapping_ptr newRule_ptr = NULL;  
    uint8_t portId = 0;
    uint8_t ifaceType = 0;
    uint8_t ifcType = 0;
    int result = 0;

    /*malloc and set value for new port mapping*/       
    newRule_ptr = (omciGemPortMapping_ptr)calloc(1 , sizeof(omciGemPortMapping_t));
    if(newRule_ptr == NULL){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]->calloc newRule_ptr  fail\n",__FUNCTION__,__LINE__);
        goto end;
    }

    /*get ANI/UNI port id*/
    result = getPortFromMacBridgeByInstId(&portId, &ifaceType, instId);
    if(result != 0){//don't need add rule
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]->not ANI/UNI port\n",__FUNCTION__,__LINE__);
        ret = 0;
        goto end;
    }
    if(ifaceType == OMCI_MAC_BRIDGE_PORT_WAN_IFC){//WAN side
        delMatchFlag = OMCI_GEMPORT_MAPPING_ANI_PORT;
        newRule_ptr->aniPort = portId;
    }else{//LAN side
        result = getMacBridgePortInstType(instId, &ifcType);
        if((result == OMCI_MAC_BRIDGE_PORT_LAN_IFC)
            && ((ifcType == OMCI_MAC_BRIDGE_PORT_PPTP_UNI)
#ifdef TCSUPPORT_PON_IP_HOST
                || (ifcType == OMCI_MAC_BRIDGE_PORT_IP_CONFIG_HOST)
#endif
        ))
        {
            delMatchFlag = OMCI_GEMPORT_MAPPING_USERPORT;
            newRule_ptr->userPort = portId;
        }       
        else  // when delete other type's LAN iface, directly exit, added by lidong
        {
            ret = 0;
            goto end;
        }
    }   
    if(delOmciGemPortMappingRuleByMatchFlag(delMatchFlag, newRule_ptr) != 0){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]->delOmciGemPortMappingRuleByMatchFlag, fail\n",__FUNCTION__,__LINE__);
        goto end;
    }
    
    ret = 0;
end:

	if(newRule_ptr != NULL){
		free(newRule_ptr);
		newRule_ptr = NULL;
	}
    return ret;
}


static void setUserIsolateApi(void *arg){
	pthreadArgUserIso_p pthreadArg_p = NULL;

	if(!TCSUPPORT_PON_USER_ISOLATION_VAL)
		goto end;
	
	if (arg == NULL)
		return;
	pthreadArg_p = (pthreadArgUserIso_p)arg;	

	switch(pthreadArg_p->action){
		case OMCI_USER_ISOLATION_DISABLE:
			pon_disable_user_group();
			break;
		case OMCI_USER_ISOLATION_ENABLE:
			pon_enable_user_group();
			break;
		case OMCI_USER_ISOLATION_SET_GROUP:
			pon_set_user_group((pthreadArg_p->portId + 1), pthreadArg_p->group);
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"%s [%d] API->portid=%d, group=0x%02x [%d]\n",__FUNCTION__,__LINE__, pthreadArg_p->portId, pthreadArg_p->group, __LINE__);
			break;			
		default:
			break;		
	}
end:	
	if(arg != NULL){
		free(arg);
		arg = NULL;
	}
	return;
}

/*******************************************************************************************
**function name
	userIsolateApi
**description:
	create thread to set user isolate API
 **retrun :
 	-1:	failure
 	0:	success
**parameter:
	action:	user isolate API type
	portId :	lan port id(0~3)
  	group :	group id
********************************************************************************************/
int userIsolateApi(uint8_t action, uint8_t portId, uint32_t group){
	int ret = -1;
	pthreadArgUserIso_p pthreadArg_p = NULL;	
//	pthread_t thread_id;
//	pthread_attr_t thread_attr;
	uint8_t supportFlag = 0;

	if(!TCSUPPORT_PON_USER_ISOLATION_VAL)
		return 0;

	switch(action){
//		case OMCI_USER_ISOLATION_DISABLE:
//		case OMCI_USER_ISOLATION_ENABLE:
		case OMCI_USER_ISOLATION_SET_GROUP:
			if(portId <= OMCI_USER_ISOLATION_MAX_PORT){
				supportFlag = 1;
			}
			break;
		default:
			break;		
	}
	if(supportFlag != 1){
		ret = -1;
		goto end;
	}
	pthreadArg_p =	(pthreadArgUserIso_p) calloc(1 , sizeof(pthreadArgUserIso_t));
	if(pthreadArg_p == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR,"%s [%d] calloc fail!\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}
	memset(pthreadArg_p, 0, sizeof(pthreadArgUserIso_t));	
	pthreadArg_p->action = action;
	pthreadArg_p->portId = portId;
	pthreadArg_p->group = group;
#if 0	
	pthread_attr_init(&thread_attr);
	pthread_attr_setstacksize(&thread_attr, 16384);
	pthread_attr_setdetachstate(&thread_attr,PTHREAD_CREATE_DETACHED); 
	
	if( pthread_create(&thread_id, &thread_attr, (void *)setUserIsolateApi, (void*)pthreadArg_p) != 0 ){
		fprintf(stderr, "pthread_create setUserIsolateApi error!!\n");
		if(pthreadArg_p != NULL){
			free(pthreadArg_p);
			pthreadArg_p = NULL;
		}
		exit(0);
	}
	//	pthread_attr_destroy(&thread_attr);
#endif
	setUserIsolateApi(pthreadArg_p);
	ret = 0;
end:
	return ret;
}
/*******************************************************************************************************************************
9.3.1 MAC Bridge Service Profile ME

********************************************************************************************************************************/

int setMBSPLearningIndValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	uint8_t learningInd = 0;
	omci_mac_br_service_ptr mac_br_srv_p = NULL;
	int	ret = 0;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d] setMBSPLearningIndValue start\n",__FUNCTION__,__LINE__);	
    if(me_info == NULL || omci_attr == NULL){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	mac_br_srv_p = (omci_mac_br_service_ptr)me_info->attributes;
    if(mac_br_srv_p == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	learningInd = mac_br_srv_p->learnInd;
	bbf247_set_maclearn_flag(learningInd);
	//if(learningInd != 1){/*only support set enabled, and it is always 1.*/
	//	ret = -1;
	//	goto end;
	//}

end:
	return ret;
}

int getMBSPPortBridingIndValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){

	uint8_t val  = 0;
	uint8_t mask[MAX_ETH_PORT_NUM_ARRAY] = {0};
	omci_mac_br_service_ptr mac_br_srv_p = NULL;
	int ret = -1;

    if(me_info == NULL || omci_attr == NULL){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	mac_br_srv_p = (omci_mac_br_service_ptr)me_info->attributes;	
    if(mac_br_srv_p == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	if(((macMT7530GetPortBrgInd(OMCI_MAC_BRIDGE_LAN_PORT1, &mask[0]) == 0)	&& ((mask[0] & MAX_OMCI_LAN_PORT_MASK)== MAX_OMCI_LAN_PORT_MASK))
		&& ((macMT7530GetPortBrgInd(OMCI_MAC_BRIDGE_LAN_PORT2, &mask[1]) == 0)	&& ((mask[1] & MAX_OMCI_LAN_PORT_MASK)== MAX_OMCI_LAN_PORT_MASK))
		&& ((macMT7530GetPortBrgInd(OMCI_MAC_BRIDGE_LAN_PORT3, &mask[2]) == 0)	&& ((mask[2] & MAX_OMCI_LAN_PORT_MASK)== MAX_OMCI_LAN_PORT_MASK))
		&& ((macMT7530GetPortBrgInd(OMCI_MAC_BRIDGE_LAN_PORT4, &mask[3]) == 0)	&& ((mask[3] & MAX_OMCI_LAN_PORT_MASK)== MAX_OMCI_LAN_PORT_MASK))){
		val = 1;
	}else{
		val = 0;
	}
#if 0
	for(i = 0; i<MAX_ETH_PORT_NUM; i++){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n getMBSPPortBridingIndValue mask[%d]= 0x02x", i, mask[i]);	
	}
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n getMBSPPortBridingIndValue val = %d", val);
#endif
	mac_br_srv_p->portBrInd = val;
	ret = 0;
end:
	return ret;	
}


int setMBSPPortBridingIndValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	uint8_t portBridgingInd = 0;
	int	ret = 0;
	uint8_t mask[MAX_ETH_PORT_NUM_ARRAY] = {0};
	int i = 0;
	omci_mac_br_service_ptr mac_br_srv_p = NULL;
	int real_max_eth_port_num = MAX_ETH_PORT_NUM_ARRAY < MAX_ETH_PORT_NUM ?MAX_ETH_PORT_NUM_ARRAY:MAX_ETH_PORT_NUM;

    if(me_info == NULL || omci_attr == NULL){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	mac_br_srv_p = (omci_mac_br_service_ptr)me_info->attributes;	
    if(mac_br_srv_p == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	if(omci_info_g.onuType != HGU) //2--hgu modes
	{
	portBridgingInd = mac_br_srv_p->portBrInd;
	switch(portBridgingInd){
		case 0:
			for(i = 0; i<real_max_eth_port_num; i++){
				mask[i] = (OMCI_LAN_PORT1_OTHER_MASK | (1<<i));
			}
			break;
		case 1:
			for(i = 0; i<real_max_eth_port_num; i++){
				mask[i] = MAX_OMCI_LAN_PORT_DEFAULT_MASK;
			}
			break;
		default:
			ret = -1;
			goto end;
			break;
	
	}

	for(i = 0; i<real_max_eth_port_num - 1; i++){
		if(macMT7530SetPortBrgInd(i, mask[i]) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]->macMT7530SetPortBrgInd mask[%d]= 0x%02x, fail\n",__FUNCTION__,__LINE__,i, mask[i]);
		}
	}
	}

	ret = 0;

end:
	return ret;
}


/*The boolean value true specifies that MAC frames with unknown destination addresses be discarded
   The value false specifies that such frames be forwarded to all allowed ports.
*/
int getMBSPUnKnownMacAddrDiscardValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){

	uint8_t val  = 0;
	int ret = 0;
	omci_mac_br_service_ptr mac_br_srv_p = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);		
    if(me_info == NULL || omci_attr == NULL){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	mac_br_srv_p = (omci_mac_br_service_ptr)me_info->attributes;	
    if(mac_br_srv_p == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	if((macMT7530GetDiscardUnknownMacInd(OMCI_MAC_BRIDGE_LAN_PORT1) == OMCI_MAC_BRIDGE_ENABLE_DISCARD)
		&& (macMT7530GetDiscardUnknownMacInd(OMCI_MAC_BRIDGE_LAN_PORT2) == OMCI_MAC_BRIDGE_ENABLE_DISCARD)
		&& (macMT7530GetDiscardUnknownMacInd(OMCI_MAC_BRIDGE_LAN_PORT3) == OMCI_MAC_BRIDGE_ENABLE_DISCARD)
		&& (macMT7530GetDiscardUnknownMacInd(OMCI_MAC_BRIDGE_LAN_PORT4) == OMCI_MAC_BRIDGE_ENABLE_DISCARD)
		){
		val = 1;
	}else{
		val = 0;
	}	
	mac_br_srv_p->unkMACAddrDis = val;

	ret = 0;
end:	
	return ret;
}

int setMBSPUnKnownMacAddrDiscardValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){

	uint8_t unKnownMacAddrDiscard = 0;
	uint8_t ind = 0;
	int	ret = 0;
	omci_mac_br_service_ptr mac_br_srv_p = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);		
    if(me_info == NULL || omci_attr == NULL){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	mac_br_srv_p = (omci_mac_br_service_ptr)me_info->attributes;	
    if(mac_br_srv_p == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	unKnownMacAddrDiscard = mac_br_srv_p->unkMACAddrDis;
	if(unKnownMacAddrDiscard == 0){
		ind = OMCI_MAC_BRIDGE_DISABLE_DISCARD;
	}else if(unKnownMacAddrDiscard == 1){
		ind = OMCI_MAC_BRIDGE_ENABLE_DISCARD;
	}else{
		ret = -1;
		goto end;
	}
	
	if((macMT7530SetDiscardUnknownMacInd(OMCI_MAC_BRIDGE_LAN_PORT1, ind) == 0)
		&& (macMT7530SetDiscardUnknownMacInd(OMCI_MAC_BRIDGE_LAN_PORT2, ind) == 0)
		&& (macMT7530SetDiscardUnknownMacInd(OMCI_MAC_BRIDGE_LAN_PORT3, ind) == 0)
		&& (macMT7530SetDiscardUnknownMacInd(OMCI_MAC_BRIDGE_LAN_PORT4, ind) == 0)
		){
		ret = 0;
	}else{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d] macMT7530SetDiscardUnknownMacInd fail\n",__FUNCTION__,__LINE__);
	}

	ret = 0;
end:	
	return ret;
}


int setMBSPMacAddrLimitValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	int	ret = 0;
	uint8_t macAddrLimitFromMBSP = 0;
#ifdef TCSUPPORT_BRIDGE_MAC_LIMIT
	char cmd[64];
#endif
	omci_mac_br_service_ptr mac_br_srv_p = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);		
    if(me_info == NULL || omci_attr == NULL){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	mac_br_srv_p = (omci_mac_br_service_ptr)me_info->attributes;	
    if(mac_br_srv_p == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	macAddrLimitFromMBSP = mac_br_srv_p->MACLearnDepth;
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG, "%s [%d] macAddrLimit=%d\n",__FUNCTION__,__LINE__,macAddrLimitFromMBSP); 
#ifdef TCSUPPORT_BRIDGE_MAC_LIMIT
	if(HGU != omci_info_g.onuType)
	{
		/* set mac limit total */
		sprintf(cmd,"echo %d > /proc/br_fdb/mac_limit_total",macAddrLimitFromMBSP);
		system(cmd);
		pon_clean_hwnat();  //system("/userfs/bin/hw_nat -!");
        omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d] set mac bridge service profile learning depth %d\n",__FUNCTION__,__LINE__,macAddrLimitFromMBSP);	
	}
#endif
	ret = 0;
end:
	return ret;
}

/*******************************************************************************************************************************
9.3.2 MAC Bridge Configuration Data ME

********************************************************************************************************************************/

int getMBCDBridgeMACAddrValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	int ret = -1;
	omci_mac_br_cfg_data_ptr mac_br_cfg_data_p = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);		
    if(me_info == NULL || omci_attr == NULL){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	mac_br_cfg_data_p = (omci_mac_br_cfg_data_ptr)me_info->attributes;	
    if(mac_br_cfg_data_p == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
		
	getOmciEtherAddr((uint8_t *)mac_br_cfg_data_p->brMACAddr);

	ret = 0;
end:
	return ret;
}

int getMBCDBridgePriorityValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	int ret = 0;
	omci_mac_br_cfg_data_ptr mac_br_cfg_data_p = NULL;
	omci_me_info_t mac_srv_me_info = {0};
	omci_mac_br_service_ptr mac_br_srv_p = NULL;

	/* same with 9.3.1*/
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);		
    if(me_info == NULL || omci_attr == NULL){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	mac_br_cfg_data_p = (omci_mac_br_cfg_data_ptr)me_info->attributes;	
    if(mac_br_cfg_data_p == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	
	mac_srv_me_info.class_id = OMCI_CLASS_ID_MAC_BRIDGE_SERVICE_PROFILE;
	mac_srv_me_info.inst_id = me_info->inst_id;
	if(omci_attr_get_all_data_except_table_attr(&mac_srv_me_info) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}
	mac_br_srv_p = (omci_mac_br_service_ptr)mac_srv_me_info.attributes;
	if(NULL == mac_br_srv_p){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->mac_br_srv_p calloc fail\n",__FUNCTION__);
		ret = -1;
		goto end;
	}
	mac_br_cfg_data_p->brPriority = mac_br_srv_p->priority;
	
	ret = 0;
end:
	return ret;
}


int getMBCDDesignatedRootValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	uint8_t macAddr[6] = {0};
	int ret = -1;
	omci_mac_br_cfg_data_ptr mac_br_cfg_data_p = NULL;
	omci_me_info_t mac_srv_me_info = {0};
	omci_mac_br_service_ptr mac_br_srv_p = NULL;

	/* priorty  same with 9.3.1*/	
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);		
    if(me_info == NULL || omci_attr == NULL){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	mac_br_cfg_data_p = (omci_mac_br_cfg_data_ptr)me_info->attributes;	
    if(mac_br_cfg_data_p == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

	mac_srv_me_info.class_id = OMCI_CLASS_ID_MAC_BRIDGE_SERVICE_PROFILE;
	mac_srv_me_info.inst_id = me_info->inst_id;
	if(omci_attr_get_all_data_except_table_attr(&mac_srv_me_info) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}
	mac_br_srv_p = (omci_mac_br_service_ptr)mac_srv_me_info.attributes;
	if(NULL == mac_br_srv_p){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->mac_br_srv_p calloc fail\n",__FUNCTION__);
		ret = -1;
		goto end;
	}
	
	mac_br_cfg_data_p->designatedRoot[0] = (uint8_t)mac_br_srv_p->priority;
	mac_br_cfg_data_p->designatedRoot[1] = (uint8_t)(mac_br_srv_p->priority >> 8);
	
	getOmciEtherAddr(macAddr);
	memcpy(mac_br_cfg_data_p->designatedRoot+2, macAddr, 6);

	ret = 0;
end:
	return ret;
}

int getMBCDRootPathCostValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	uint32_t costValue = 0x00000000;/*this bridge is root bridge, so return 0*/
	omci_mac_br_cfg_data_ptr mac_br_cfg_data_p = NULL;
	int ret = -1;

	/* same with 9.3.1*/
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);		
    if(me_info == NULL || omci_attr == NULL){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	mac_br_cfg_data_p = (omci_mac_br_cfg_data_ptr)me_info->attributes;	
    if(mac_br_cfg_data_p == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	mac_br_cfg_data_p->rootPathCost = costValue;

	ret = 0;
end:
	return ret;

}

/*******************************************************************************************
**function name
	getMacBridgePortCnt
**description:
	It records the number of ports linked to this bridge
 **retrun :
 	0:	success
 	-1:	failure
**parameter:
  	instId: instance id in mac bridge service profile ME.
  	portCnt: port numbers.
********************************************************************************************/
static int getMacBridgePortCnt(uint16_t instanceId, uint8_t * portCnt){
	uint8_t bridgePortCnt = 0;
	uint16_t bridgeInstId = 0;
	uint16_t *inst_id_array = NULL;
	int inst_count = 0, i = 0;
	omci_me_info_t me_info = {0};
	omci_mac_br_port_cfg_ptr mac_br_attr = NULL;
	int ret = -1;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);		
	if(portCnt == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]--> Parameter portCnt is null, fail\n",__FUNCTION__,__LINE__); 	
        ret = -1;
        goto end;
	}
	if(omci_lib_get_inst_count_by_classid(me_info.class_id, &inst_count) != 0 || inst_count == 0){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_WARN, "[%s][%d] me_info.class_id = %d do not exist.\n",__FUNCTION__,__LINE__,me_info.class_id);
        return 0;
	}
	inst_id_array = malloc(sizeof(uint16_t) * inst_count);
	if(inst_id_array == NULL || (omci_lib_get_inst_list_by_classid(me_info.class_id, inst_id_array, inst_count) == -1)){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]--> malloc inst_id_array fail\n",__FUNCTION__,__LINE__); 	
        ret = -1;
        goto end;
	}

	for(i = 0; i < inst_count; i++){
		/*3.1 get 9.3.4 instance id*/
		me_info.inst_id = inst_id_array[i];
		if(omci_attr_get_all_data_except_table_attr(&me_info) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
			continue;
		}
		
		mac_br_attr = (omci_mac_br_port_cfg_ptr)me_info.attributes;
		if(NULL == mac_br_attr){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]->mac_br_attr calloc fail\n",__FUNCTION__,__LINE__);
			continue;
		}
		bridgeInstId = mac_br_attr->bridgeIDPointer;
		if(bridgeInstId == instanceId){
			bridgePortCnt++;
		}
	}
	
	*portCnt = bridgePortCnt;
	ret = 0;

end:
    if(inst_id_array != NULL)
    {
        free(inst_id_array);
    }
	return ret;
}

int getMBCDBridgePortCountValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	int ret = -1;
	uint16_t instanceId = 0;
	uint8_t portCnt = 0;
	omci_mac_br_cfg_data_ptr mac_br_cfg_data_p = NULL;
	
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);		
    if(me_info == NULL || omci_attr == NULL){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	mac_br_cfg_data_p = (omci_mac_br_cfg_data_ptr)me_info->attributes;	
    if(mac_br_cfg_data_p == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	
	instanceId = me_info->inst_id;	
	ret = getMacBridgePortCnt(instanceId, &portCnt);
	if(ret != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]->getMacBridgePortCnt fail\n",__FUNCTION__,__LINE__);
		goto end;
	}
	
	mac_br_cfg_data_p->brPortCnt= portCnt;

	ret = 0;
end:
	return ret;
}

int getMBCDRootPortNumValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	uint16_t portNum = 0x0000;/*this bridge is root bridge, so return 0*/
	omci_mac_br_cfg_data_ptr mac_br_cfg_data_p = NULL;
	int ret = -1;

	/* same with 9.3.1*/
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);		
    if(me_info == NULL || omci_attr == NULL){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	mac_br_cfg_data_p = (omci_mac_br_cfg_data_ptr)me_info->attributes;	
    if(mac_br_cfg_data_p == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	mac_br_cfg_data_p->rootPortNum= portNum;
	ret = 0;
end:
	return ret;
}

/*******************************************************************************************************************************
9.3.3 MAC bridge performance monitoring history data ME

********************************************************************************************************************************/

int setMBPMHDThresholdDataIdValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){

#if 0 //because the function don't support , so the threshold doesn't support also.
	thresholdMeId = get16(attributeValuePtr);

	ret = getThresholdDataValue(OMCI_CLASS_ID_THRESHOLD_DATA1,thresholdMeId, 1, &thresholdData);
	if (ret != 0)
		return -1;
	memset(tempBuffer, 0, sizeof(tempBuffer));
	sprintf(tempBuffer, "%x", thresholdData);
	ret = omciPmmgrSet( tmpomciMeInst_p->classId, tmpomciMeInst_p->deviceId, PMMGR_THRESHOLD, 1, tempBuffer);
	if (ret != 0)
		return -1;
#endif

	return 0;
}

/*******************************************************************************************************************************
9.3.4 MAC bridge port configuration data

********************************************************************************************************************************/

int setMBPCDTPTypeValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	int ret = -1;
	uint8_t tpType = 0;
	omci_mac_br_port_cfg_ptr mac_br_attr = NULL;

    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

	mac_br_attr = (omci_mac_br_port_cfg_ptr)me_info->attributes;
    if(mac_br_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	tpType = mac_br_attr->tpType;
	switch(tpType){
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_1:
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_3:
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_4:
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_5:
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_6:
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_11:
			break;
		default:// others not support
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d] -> value is error, tpType=%d, fail\n",__FUNCTION__,__LINE__,tpType);
			ret = -1;
			goto end;
	}
	
	ret = 0;
end:
	return ret;
}


/*******************************************************************************************
**function name
    addGemPortMappingRuleByAniPort
**description:
    add gem port mapping ruel by ani port (not include 802.1p mode)
 **retrun :
    -1: failure
    0:  success
**parameter:
    instId: 9.3.4 instance id
********************************************************************************************/
static int addGemPortMappingRuleByAniPort(IN uint16_t instId){
    int ret = -1;
    omciGemPortMapping_ptr newRule_ptr = NULL;  
    uint32_t classIdInstId = 0;
    uint8_t portId = 0;
    uint8_t ifaceType = 0;
    uint16_t gemPortList[MAX_MAC_BRIDGE_PORT_GEM_PORT_NUM] = {0};
    uint8_t validGemPortNum = 0;
    int result = 0;
    uint8_t ifcType = 0;
    
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    /*get ME id(class id +instance id)*/
    classIdInstId = (OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA<<16);
    classIdInstId |= instId;

    /*don't support 802.1p */
    result = getMacBridgePortInstType(instId, &ifcType);
    if(result != OMCI_MAC_BRIDGE_PORT_WAN_IFC){// UNI side don't need conside.
        ret = 0;
        goto end;
    }else{
        if(ifcType == OMCI_MAC_BRIDGE_PORT_DOT1P){// update 802.1p
            ret = 0;
	    	if(updateGemMappingRuleByMbPortANI(instId) != 0){
	        	omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]updateGemMappingRuleByMbPortUNI, fail\n",__FUNCTION__,__LINE__);
	    	}
            goto end;
        }
    }
    
    /*get ANI port id*/
    result = getPortFromMacBridgeByInstId(&portId, &ifaceType, instId);
    if((result != 0) || (ifaceType != OMCI_MAC_BRIDGE_PORT_WAN_IFC)){//don't need add rule
        omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]->not ANI port\n",__FUNCTION__,__LINE__);
        ret = 0;
        goto end;
    }

    /*get gem port id*/
    if(getGemPortByMACBridgePortInst(instId, gemPortList, &validGemPortNum) != 0){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]->getGemPortByMACBridgePortInst,, instId=%d, fail\n",__FUNCTION__,__LINE__,instId);
        ret = -1;
        goto end;
    }
    /*only support ANI mac bridge port point to the gem port*/
    if(validGemPortNum != 1){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]->validGemPortNum=%d, fail\n",__FUNCTION__,__LINE__,validGemPortNum);
        ret = 0;
        goto end;
    }
    
    /*malloc and set value for new port mapping*/       
    newRule_ptr = (omciGemPortMapping_ptr)calloc(1 , sizeof(omciGemPortMapping_t));
    if(newRule_ptr == NULL){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]->calloc newRule_ptr  fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

    newRule_ptr->tagctl = (OMCI_GEMPORT_MAPPING_ANI_PORT
                        |OMCI_GEMPORT_MAPPING_GEMPORT
                        |OMCI_GEMPORT_MAPPING_CLASSID_INSTID);

//  newRule_ptr->tagFlag = OMCI_GEMPORT_MAPPING_UNTAGGED_FLAG;
    newRule_ptr->aniPort = portId;
    newRule_ptr->gemPort = gemPortList[0];  
    newRule_ptr->classIdInstId = classIdInstId;
    if(addOmciGemPortMappingRule(newRule_ptr) != 0){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]-> addOmciGemPortMappingRule  untagged, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
    
    ret = 0;
end:
	if(newRule_ptr != NULL){
		free(newRule_ptr);
		newRule_ptr = NULL;
	}
    return ret;
}


/*******************************************************************************************
**function name
	setMacBridgePortInfoToRomfile
**description:
	set mac bridge port information to romfile(interface type(0/1), port list)
 **retrun :
 	-1:	fail
 	0:	success
**parameter:
	instanceId:	9.3.4 instance id
********************************************************************************************/

int setMacBridgePortInfoToRomfile(IN uint16_t instanceId){
	int ret = -1;
	int i = 0, j= 0;
	uint16_t gemPortList[MAX_MAC_BRIDGE_PORT_GEM_PORT_NUM] = {0};
	uint8_t validGemPortNum = 0;
	uint8_t ifaceType = 0; //0:UNI, 1:ANI	
	uint8_t portId = 0;//UNI/ANI port id
	
	/*get interface type and port id*/
	if(getPortFromMacBridgeByInstId(&portId, &ifaceType, instanceId) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n setMacBridgePortInfoToRomfile->getPortFromMacBridgeByInstId fail, portId=%d,ifaceType=%d,instanceId=%d",
			portId,ifaceType,instanceId);
		goto end;;
	}

	/*don't support interface type*/
	if((ifaceType != OMCI_MAC_BRIDGE_PORT_LAN_IFC)
		&& (ifaceType != OMCI_MAC_BRIDGE_PORT_WAN_IFC)){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n setMacBridgePortInfoToRomfile->getPortFromMacBridgeByInstId, instanceId=%d, ifaceType=%d, fail",instanceId,ifaceType);
		goto end;
	}

	/*get attribute information*/
	if(ifaceType == OMCI_MAC_BRIDGE_PORT_LAN_IFC){//UNI port
	
	}else if(ifaceType == OMCI_MAC_BRIDGE_PORT_WAN_IFC){//ANI port
		if(getGemPortByMACBridgePortInst(instanceId, gemPortList, &validGemPortNum) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n setMacBridgePortInfoToRomfile->getGemPortByMACBridgePortInst,, instanceId=%d, fail",instanceId);
			goto end;
		}			
//		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n setMacBridgePortInfoToRomfile->omciPmmgrGet, instanceId=%d, validGemPortNum=%d",instanceId,validGemPortNum);
	}
	
	for(i = 0; i < MAX_GEM_PORT_NUM; i++)
	{
		if((ani_uni_port[i].valid == 0) || (ani_uni_port[i].valid == 1 && ani_uni_port[i].index == instanceId)){
			ani_uni_port[i].index = instanceId;
			ani_uni_port[i].ifaceType = ifaceType;
			ani_uni_port[i].lan_portId = portId;
			for(j = 0; j<validGemPortNum; j++){
				ani_uni_port[i].gemPortList[j] = gemPortList[j];
			}
			ani_uni_port[i].gemNum = validGemPortNum;
			ani_uni_port[i].valid = 1;
			break;
		}
	}
	ret = 0;
	
end:
	return ret;
}
static int getGemportUnibyMBSP(IN uint16_t instId,OUT uint16_t * uniList, OUT uint8_t * num)
{
	int i = 0;
	int instCnt = 0;
	omci_me_info_t me_info = {0};
	uint16_t MBPCD_inst_array[MAX_INST_COUNT]={0};
	omci_mac_br_port_cfg_ptr mac_br_attr = NULL;
	
	if(omci_lib_get_inst_count_by_classid(OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA,&instCnt) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
		return -1;	
	}

	if(omci_lib_get_inst_list_by_classid(OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA,MBPCD_inst_array,instCnt) <= 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
		return -1;	
	}

	for(i=0; i<instCnt; i++){
		me_info.class_id = OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA;
		me_info.inst_id = MBPCD_inst_array[i];
		if(omci_attr_get_all_data_except_table_attr(&me_info) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
			continue;		
		}		
		mac_br_attr = (omci_mac_br_port_cfg_ptr)(me_info.attributes);
		if(mac_br_attr->bridgeIDPointer == instId && mac_br_attr->tpType == OMCI_MAC_BRIDGE_PORT_TP_TYPE_1){
			uniList[(*num)] = MBPCD_inst_array[i];
			(*num)++;
		}			
	}

	return 0;
}
/*******************************************************************************************
**function name
	updateMACBridgePortInfoByAssociaAttr
**description:
	1.update multicast rule and set 9.3.4 tp type or tp pointer attribute.
	2.update PM instance in PM mechanism
	3.update device id of the mac bridge ANI port
	4.update gem port mapping
 **retrun :
 	-1:	failure
 	0:	success
**parameter:
  	value :	set value
  	meInstantPtr: 		instance pointer
  	omciAttribute:		attribute pointer
  	flag:				create  or set
  	attrType:		 	tp type attribute or tp pointer attribute
********************************************************************************************/
static int updateMACBridgePortInfoByAssociaAttr(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr, uint8_t attrType){
	int ret = -1;
	int result = 0;
	uint16_t instanceId = 0;
	uint16_t uniInstid = 0;
	uint8_t newPortType = 0;
	uint8_t i = 0;
	uint16_t mbInstId = 0; 
	uint8_t newIfcType = 0;
	uint8_t portId = 0;
	uint16_t uniList[MAX_MAC_BRIDGE_PORT_UNI_PORT_NUM] = {0};
    uint8_t validUniPortNum = 0;
#ifdef TCSUPPORT_TLS
	uint8_t learnInd = 0;
	omci_me_info_t mb_srv_info = {0};
	omci_mac_br_service_ptr mac_br_srv_p = NULL;
#endif
	omci_mac_br_port_cfg_ptr mac_br_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

	switch(attrType){
		case OMCI_MAC_BRIDGE_PORT_TP_TYPE_ATTR:
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]-> TP Type start\n",__FUNCTION__,__LINE__);
			break;
		case OMCI_MAC_BRIDGE_PORT_TP_POINTE_ATTR:
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]-> TP Pointer start\n",__FUNCTION__,__LINE__);
			break;
		default:
			ret = -1;
			goto end;
			break;
	}

	instanceId = me_info->inst_id;
	mac_br_attr = (omci_mac_br_port_cfg_ptr)me_info->attributes;
    if(mac_br_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

	/*get mac bridge service profile instance id*/
	mbInstId = mac_br_attr->bridgeIDPointer;

	/*get new mac bridge port interface type*/
	result = getMacBridgePortInstType(instanceId,&newIfcType);
	if(result == OMCI_MAC_BRIDGE_PORT_WAN_IFC){
		newPortType = OMCI_MAC_BRIDGE_PORT_WAN_IFC;
	}else if(result == OMCI_MAC_BRIDGE_PORT_LAN_IFC){
		newPortType = OMCI_MAC_BRIDGE_PORT_LAN_IFC;
	}else{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]-> getMacBridgePortInstType,newPortType, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
		goto end;
	}
	 /*get UNI port id*/
	 if(newIfcType == OMCI_MAC_BRIDGE_PORT_GEM_TP){
		if(getGemportUnibyMBSP(mbInstId,uniList,&validUniPortNum) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]->getGemportUnibyMBSP,, instId=%d, fail\n",__FUNCTION__,__LINE__,mbInstId);
		}
	}
	/*update some information when create mac bridge port instance*/
	if((me_info->msg_type == MT_OMCI_MSG_TYPE_CREAT) && (attrType == OMCI_MAC_BRIDGE_PORT_TP_POINTE_ATTR)){
		/*3.update device id of the mac bridge ANI port*/
		if(newPortType == OMCI_MAC_BRIDGE_PORT_WAN_IFC){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]-> newPortType=%d\n",__FUNCTION__,__LINE__,newPortType);
			if(setMacBridgePortDeviceId(instanceId, OMCI_ADD_MAC_BRIDGE_ANI_PORT) == OMCI_MAC_BRIDGE_PORT_FAIL){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]-> setMacBridgePortDeviceId, add1, fail\n",__FUNCTION__,__LINE__);
			}
		//added by lidong	
			if (newIfcType == OMCI_MAC_BRIDGE_PORT_MULTICAST_TP)
			{
				//nothing
			}
			else{ 
				if(addGemPortMappingRuleByAniPort(instanceId) != 0){
				/*4.update gem port mapping*/
				/*4.1 add gem port mapping rule by ani port*/
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]->create-> addGemPortMappingRuleByAniPort, fail\n",__FUNCTION__,__LINE__);
			}
				if(validUniPortNum != 0){
					for(i = 0;i < validUniPortNum;i++){
						uniInstid = uniList[i];
						if(updateGemPortRuleByMbPortUNIandANI(uniInstid,instanceId) != 0){
							omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]->create-> addGemPortRuleByMbPortUNI, fail\n",__FUNCTION__,__LINE__);
						}	
					}
				}
			}
		}
		else
		{	//newPortType = OMCI_MAC_BRIDGE_PORT_LAN_IFC
			/*add gem port rule according to the 9.3.4 point to the PPTP UNI*/
			if(addGemPortRuleByMbPortUNI(instanceId) != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]->create-> addGemPortRuleByMbPortUNI, fail\n",__FUNCTION__,__LINE__);
			}
		}
		
	}

	/*update mac bridge port information for PM in romfile*/
	if((me_info->msg_type == MT_OMCI_MSG_TYPE_CREAT) && (attrType == OMCI_MAC_BRIDGE_PORT_TP_TYPE_ATTR)){
		//nothing
	}else{	
		if(setMacBridgePortInfoToRomfile(instanceId) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]-> setMacBridgePortInfoToRomfile, fail\n",__FUNCTION__,__LINE__);
		}

		/*set user isolate function to related group  in this lan port*/
		if((newPortType == OMCI_MAC_BRIDGE_PORT_LAN_IFC) \
            && (newIfcType == OMCI_MAC_BRIDGE_PORT_PPTP_UNI) \
            && (omci_info_g.onuType==SFU)){
			if(getMacBridgeLanPortId(instanceId, &portId) == 0){
#ifdef TCSUPPORT_PON_USER_ISOLATION				
				if(userIsolateApi(OMCI_USER_ISOLATION_SET_GROUP, portId, mbInstId) != 0){
					omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]-> userIsolateApi,new lan port id, fail\n",__FUNCTION__,__LINE__);
				}
#endif
			}else{
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]-> getMacBridgeLanPortId,new lan port id, fail\n",__FUNCTION__,__LINE__);
			}
		}
	}

#ifdef TCSUPPORT_TLS
    /* add for TLS function */
    if((OMCI_MAC_BRIDGE_PORT_TP_POINTE_ATTR == attrType ) && (newIfcType == OMCI_MAC_BRIDGE_PORT_PPTP_UNI ) )
    {
        /*get mac learn ind from mac bridge service profile */
		mb_srv_info.class_id = OMCI_CLASS_ID_MAC_BRIDGE_SERVICE_PROFILE;
		mb_srv_info.inst_id = mbInstId;
		if(omci_attr_get_all_data_except_table_attr(&mb_srv_info) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
			ret = -1;
			goto end;
		}
		mac_br_srv_p = (omci_mac_br_service_ptr)mb_srv_info.attributes;
		if(NULL == mac_br_srv_p){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->mac_br_attr calloc fail\n",__FUNCTION__);
			ret = -1;
			goto end;
		}
		learnInd = mac_br_srv_p->learnInd;

        /* bridge learning disable mean this PPTP ETH UNI is TLS port */
        if (0 == learnInd){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "set TLS port \n");
            if(getMacBridgeLanPortId(instanceId, &portId) == 0){
                if(OMCI_TLS_INVALID_PORT == omciTLSInfo.lanPort){
                    omcidbgPrintf(OMCI_DEBUG_LEVEL_WARN, "%s [%d] add tls port to %d by MBPCD inst %d \n",__FUNCTION__,__LINE__,portId,instanceId);
                    blapi_traffic_set_tls_port(1, portId);
                    omciTLSInfo.lanPort = portId;
                }else if (portId != omciTLSInfo.lanPort){
                    omcidbgPrintf(OMCI_DEBUG_LEVEL_WARN, "%s [%d] update tls port to %d by MBPCD inst %d\n",__FUNCTION__,__LINE__,portId,instanceId);
                    blapi_traffic_set_tls_port(1, portId);
                    omciTLSInfo.lanPort = portId;
                }
            }
        }
    }
#endif
	ret = 0;
	
end:
	return ret;
}


int setMBPCDTPPointerValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
	return updateMACBridgePortInfoByAssociaAttr(me_info, omci_attr,OMCI_MAC_BRIDGE_PORT_TP_POINTE_ATTR);
}

int getMBPCDportMacAddressValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	uint8_t portMacAddr[6] = {0,0,0,0,0,0};
	uint16_t instanceId = 0;
	int type = 0;
	int ret = -1;
	uint8_t lanPortId = 0;	
	uint8_t ifcType = 0;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	instanceId = me_info->inst_id;

	/*get interface type*/
	type = getMacBridgePortInstType(instanceId, &ifcType);
	if(type == OMCI_MAC_BRIDGE_PORT_LAN_IFC){
		/*get lan port id*/
		ret = getMacBridgeLanPortId(instanceId, &lanPortId);
		if(ret != 0){
			ret = -1;
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]->getMacBridgeLanPortId, fail\n",__FUNCTION__,__LINE__);
			goto end;
		}
		if(lanPortId <= ETH_1G_UNI_TOTAL_NUM){  
			/*switch API*/
			ret = macMT7530GetPortMac(lanPortId-1, portMacAddr);
			if(ret != 0){
	//			ret = -1;
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]->macMT7530GetPortMac, fail\n",__FUNCTION__,__LINE__);
			}
		}
	}else if(type == OMCI_MAC_BRIDGE_PORT_WAN_IFC){
		/*wan interface Port mac address, CPE mac address*/
		getOmciEtherAddr(portMacAddr);
	}else{
		ret = -1;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]->getMacBridgePortInstType, fail\n",__FUNCTION__,__LINE__);
		goto end;
	}
	
	ret = 0;
end:
	return ret;
}

static int setMBPCDTDPointerValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr, uint8_t attrIndex){
	uint16_t instanceId = 0;
	int type = 0;
	int ret = 0;
	uint8_t portId = 0;
	uint16_t oldTDInstId = 0;
	uint16_t newTDInstId = 0;
	uint8_t ifcType = 0;
	omci_mac_br_port_cfg_ptr mac_br_attr = NULL;
	omci_me_info_t old_me_info = {0};
	omci_mac_br_port_cfg_ptr old_mac_br_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	if((attrIndex != OMCI_MAC_BRIDGE_PORT_CFG_DATA_ATTR_11) 
		&& (attrIndex != OMCI_MAC_BRIDGE_PORT_CFG_DATA_ATTR_12)){

		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]-> attrIndex error, fail\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}
	
	instanceId =  me_info->inst_id;

	mac_br_attr = (omci_mac_br_port_cfg_ptr)me_info->attributes;
    if(mac_br_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	/*get 9.3.4  mac bridge port config data ME outbound TD pointer or inbound TD pointer attribute */
	old_me_info.class_id = OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA;
	old_me_info.inst_id = instanceId;
	if(omci_attr_get_old_data_except_table_attr(&old_me_info) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}
	old_mac_br_attr = (omci_mac_br_port_cfg_ptr)old_me_info.attributes;
	if(NULL == old_mac_br_attr){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->old_mac_br_attr calloc fail\n",__FUNCTION__);
		ret = -1;
		goto end;
	}
	
	if(attrIndex == OMCI_MAC_BRIDGE_PORT_CFG_DATA_ATTR_11){
		oldTDInstId = old_mac_br_attr->outboundTDPointer;
		newTDInstId = mac_br_attr->outboundTDPointer;
	}else if(attrIndex == OMCI_MAC_BRIDGE_PORT_CFG_DATA_ATTR_12){
		oldTDInstId = old_mac_br_attr->inboundTDPointer;
		newTDInstId = mac_br_attr->inboundTDPointer;
	}
	
	/*get interface type*/
	type = getMacBridgePortInstType(instanceId, &ifcType);
	if(type == OMCI_MAC_BRIDGE_PORT_LAN_IFC){//UNI
		/*get lan port id*/
		ret = getMacBridgeLanPortId(instanceId, &portId);
		if(ret != 0){
			ret = -1;
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]-> getMacBridgeLanPortId fail!\n",__FUNCTION__,__LINE__);
			goto end;
		}
		
		if(portId <= ETH_1G_UNI_TOTAL_NUM){  
			/* clear old outbound trafic descriptor by calling API*/
			if(me_info->msg_type != MT_OMCI_MSG_TYPE_CREAT){
				if(attrIndex == OMCI_MAC_BRIDGE_PORT_CFG_DATA_ATTR_11){
					ret = cleanBoundTD(portId, type, oldTDInstId, OMCI_OUT_BOUND);
				}else if(attrIndex == OMCI_MAC_BRIDGE_PORT_CFG_DATA_ATTR_12){
					ret = cleanBoundTD(portId, type, oldTDInstId, OMCI_IN_BOUND);	
				}
				if(ret != 0){
					omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]-> cleanOutBoundTD or cleanInBoundTD fail , attrIndex =%d\n",__FUNCTION__,__LINE__, attrIndex);
				}
			}	
			
			/* set outbound trafic descriptor by calling API*/
			if(attrIndex == OMCI_MAC_BRIDGE_PORT_CFG_DATA_ATTR_11){
				ret = setBoundTD(portId, type, newTDInstId, OMCI_OUT_BOUND);
			}else if(attrIndex == OMCI_MAC_BRIDGE_PORT_CFG_DATA_ATTR_12){
				ret = setBoundTD(portId, type, newTDInstId, OMCI_IN_BOUND);
			}
			if(ret != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]-> setOutBoundTD or setInBoundTD fail , attrIndex =%d\n",__FUNCTION__,__LINE__, attrIndex);
			}
		}
	}else if(type== OMCI_MAC_BRIDGE_PORT_WAN_IFC){//don't support wan interface, because there isn't this configurated method in ZTE C300 OLT.
#if 0		
		ret = getMacBridgeWanPortId(instanceId, &portId);
		if(ret != 0){
			ret = -1;
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n setMBPCDoutTDPointerValue-> getMacBridgeWanPortId fail!");
			goto end;
		}
#endif
	}else{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]-> getMacBridgePortInstType fail!\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}

	ret = 0;
end:
	return ret;
}

int setMBPCDoutTDPointerValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
	return setMBPCDTDPointerValue(me_info, omci_attr, OMCI_MAC_BRIDGE_PORT_CFG_DATA_ATTR_11);
}

int setMBPCDinTDPointerValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	return setMBPCDTDPointerValue(me_info, omci_attr, OMCI_MAC_BRIDGE_PORT_CFG_DATA_ATTR_12);
}

int setMBPCDMacAddrLimitValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	uint8_t macAddrLimit = 0;
	int ret = -1;
	uint16_t currInstId = 0;
	uint8_t ifaceType = 0; //0:UNI, 1:ANI
	uint8_t portId = 0;
#ifdef TCSUPPORT_BRIDGE_MAC_LIMIT
	char cmd[64];
	uint8_t portId_temp = 0;
#endif
	omci_mac_br_port_cfg_ptr mac_br_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

	mac_br_attr = (omci_mac_br_port_cfg_ptr)me_info->attributes;
    if(mac_br_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	macAddrLimit = mac_br_attr->macLearnDepth;

	/*2. get  instance id*/
	currInstId = me_info->inst_id;

	/*3. get port and interface type */
	if(getPortFromMacBridgeByInstId(&portId, &ifaceType, currInstId) != 0){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d]-->getPortFromMacBridgeByInstId, fail\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]-->uint8_t port=0x%02x\n",__FUNCTION__,__LINE__,portId);
    
	if((OMCI_MAC_BRIDGE_PORT_LAN_IFC == ifaceType) && (HGU != omci_info_g.onuType) && (portId <= ETH_1G_UNI_TOTAL_NUM))
    {
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"%s  set port %d mac limit %d interface type %d\n",__FUNCTION__,portId,macAddrLimit,ifaceType);
	#ifdef TCSUPPORT_BRIDGE_MAC_LIMIT
		portId_temp = portId+3;/*confirm from DASAN:olt lan port no from 0~3,onu br0 lan port no from 3~6*/
		sprintf(cmd,"echo %d-%d > /proc/br_fdb/mac_limit_by_port",portId_temp,macAddrLimit);
		system(cmd);

		pon_clean_hwnat();  //system("/userfs/bin/hw_nat -!");
	#else
		if (0 != macMT7530SetPortMacLimit(portId-1, macAddrLimit)){  
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d]-->macMT7530SetPortMacLimit, fail\n",__FUNCTION__,__LINE__);
		}
	#endif
	}
    
	ret = 0;
end:	
	return ret;	
}

extern int omci_me_vlan_filter_delete_op(management_entry_ptr me_entry, omci_me_info_ptr me_info);
extern int omci_me_ext_vlan_tag_delete_op(management_entry_ptr me_entry, omci_me_info_ptr me_info);
void delete_mac_br_port_cfg_linked_me(uint16_t instId)
{
	omci_me_info_t me_info_buf={0};
	management_entry_ptr tmp_me_entry=NULL;
	int i,inst_count=0;
	uint16_t inst_id_array[MAX_INST_COUNT]={0};
	omci_vlan_tag_ext_op_ptr ext_vlan_info = NULL;

	/*delete vlan filter if exist */
	me_info_buf.class_id = OMCI_CLASS_ID_VLAN_TAG_FILTER_DATA;
	me_info_buf.inst_id = instId;
	if(omci_attr_get_all_data_except_table_attr(&me_info_buf) == 0)
	{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_WARN, " %s [%d] linked ME: Vlan Filter Data exist\n",__FUNCTION__,__LINE__);
		tmp_me_entry = getAdptMeEntryByClassId(me_info_buf.class_id);
		omci_me_vlan_filter_delete_op(tmp_me_entry,&me_info_buf);
	}

	/*delete associate extend vlan if exist */
	memset(&me_info_buf,0,sizeof(me_info_buf));
	me_info_buf.class_id = OMCI_CLASS_ID_VLAN_TAG_EXTEND_OPERATE;
	if(omci_lib_get_inst_count_by_classid(me_info_buf.class_id, &inst_count) == 0)
	{
		if(inst_count > 0 && omci_lib_get_inst_list_by_classid(me_info_buf.class_id, inst_id_array, inst_count) > 0)
		{
			for(i = 0; i < inst_count; i++)
			{
				me_info_buf.inst_id = inst_id_array[i];
				if(omci_attr_get_all_data_except_table_attr(&me_info_buf) == 0)
				{
					ext_vlan_info = (omci_vlan_tag_ext_op_t *)me_info_buf.attributes;
					if(ext_vlan_info == NULL)
					{
						continue;
					}
					if(ext_vlan_info->associationType == OMCI_EXT_VLAN_TAG_OP_ASSOCIATION_TYPE_0
						&& ext_vlan_info->associatedMePointer == instId)
					{
						omcidbgPrintf(OMCI_DEBUG_LEVEL_WARN, " %s [%d] linked ME: Extend Vlan Operate Prof exist\n",__FUNCTION__,__LINE__);
						tmp_me_entry = getAdptMeEntryByClassId(me_info_buf.class_id);
						omci_me_ext_vlan_tag_delete_op(tmp_me_entry,&me_info_buf);
					}
				}
			}
		}
	}

	return ;
}
int omci_mac_br_port_cfg_data_delete_op(management_entry_ptr me_entry, omci_me_info_ptr me_info){
	int ret = -1;
	uint16_t instId = 0;
	int result = 0;
	uint16_t outTpPointer = 0;
	uint16_t inTpPointer = 0;
	int portType = 0;
	uint8_t portId = 0;
	uint8_t ifcType = 0;
	omci_me_info_t me_info_buf={0};
	omci_mac_br_port_cfg_ptr mac_br_attr = NULL;

    if((NULL == me_entry)||(NULL == me_info)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	
	/*get instance id*/	
	instId = me_info->inst_id;

	/*delete linked me */
	delete_mac_br_port_cfg_linked_me(instId);

	result = getMacBridgePortInstType(instId,&ifcType);
	/*delete gem port mapping rule by mac bridge port*/
	if(delGemPortMappingRuleByMbp(instId) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]-> delGemPortMappingRuleByMbp, fail\n",__FUNCTION__,__LINE__);
	}
	if(result == OMCI_MAC_BRIDGE_PORT_WAN_IFC){
		
		/*delete ANI mac bridge port*/	
		if(setMacBridgePortDeviceId(instId, OMCI_DEL_MAC_BRIDGE_ANI_PORT) == OMCI_MAC_BRIDGE_PORT_FAIL){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]->setMacBridgePortDeviceId, del, fail\n",__FUNCTION__,__LINE__);
 		}
	}

	/*clean trafic descriptor*/
	/*get 9.3.4  mac bridge port config data ME outbound TD pointerattribute */
	me_info_buf.class_id = OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA;
	me_info_buf.inst_id = instId; 	
	if(omci_attr_get_all_data_except_table_attr(&me_info_buf) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;		
	}

	mac_br_attr = (omci_mac_br_port_cfg_ptr)me_info_buf.attributes;
	if(NULL == mac_br_attr){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]->mac_br_attr calloc fail\n",__FUNCTION__,__LINE__);
		goto end;
	}
	outTpPointer = mac_br_attr->outboundTDPointer;
	
	/*get 9.3.4  mac bridge port config data ME inbound TD pointerattribute */
	inTpPointer = mac_br_attr->inboundTDPointer;

	/*get interface type*/
	portType = getMacBridgePortInstType(instId,&ifcType);
	if(portType == OMCI_MAC_BRIDGE_PORT_LAN_IFC){//UNI
		/*get lan port id*/
		if(getMacBridgeLanPortId(instId, &portId) == 0){
			if(portId <= ETH_1G_UNI_TOTAL_NUM){ 
				cleanBoundTD(portId, portType, outTpPointer, OMCI_OUT_BOUND);
				cleanBoundTD(portId, portType, inTpPointer,OMCI_IN_BOUND);

				/*set user isolate function to default value in this lan port*/
				
				if((ifcType == OMCI_MAC_BRIDGE_PORT_PPTP_UNI) \
	                && (SFU == omci_info_g.onuType)){
#ifdef TCSUPPORT_PON_USER_ISOLATION				
					if(userIsolateApi(OMCI_USER_ISOLATION_SET_GROUP, portId, OMCI_MBP_UNI_ISOLATE_DEFAULT_VAL) != 0){
						omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]-> userIsolateApi,new lan port id to default, fail\n",__FUNCTION__,__LINE__);
					}
#endif
				}
			}
		}
	}else if(portType == OMCI_MAC_BRIDGE_PORT_WAN_IFC){//don't support wan interface, because there isn't this configurated method in ZTE C300 OLT.
#if 0
		if(getMacBridgeWanPortId(instId, &portId) == 0){
			cleanBoundTD(portId, portType, outTpPointer, OMCI_OUT_BOUND);
			cleanBoundTD(portId, portType, inTpPointer,OMCI_IN_BOUND);
		}
#endif
	}else{
		//nothing
	}	
	
	ret = 0;
end:
	return ret;
}


/*******************************************************************************************************************************
9.3.5 MAC bridge port designation data

********************************************************************************************************************************/

int getMBPDDPortStateValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){

	uint8_t portState = 0;/*0:disabled, 1:listening, 2:learning, 3:forwarding, 4:blocking, 5:linkdown, 6 stp_off*/
	uint16_t instanceId = 0;
	int type = 0;
	int ret = -1;
	uint8_t lanPortId = 0;
	uint8_t ifcType = 0;
	omci_mac_br_port_dest_ptr mac_br_dest_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	mac_br_dest_attr = (omci_mac_br_port_dest_ptr)me_info->attributes;
    if(mac_br_dest_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

	instanceId = me_info->inst_id;

	/*get interface type*/
	type = getMacBridgePortInstType(instanceId, &ifcType);
	
	if(type == OMCI_MAC_BRIDGE_PORT_LAN_IFC){
		ret = getMacBridgeLanPortId(instanceId, &lanPortId);
		if(ret != 0){
			ret = -1;
			goto end;
		}
		if(lanPortId <= ETH_1G_UNI_TOTAL_NUM){		
			/* lan interface switch API*/
			ret = macMT7530GetPortStatus(lanPortId-1);
			if(ret == -1){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]->macMT7530GetPortStatus, fail\n",__FUNCTION__,__LINE__);
				portState = OMCI_MAC_BRIDGE_PORT_STATE_6;//stp_off
			}else{
				portState = (uint8_t)ret;
			}
		}else{
			ret = -1;
			goto end;
		}		
	}else if(type== OMCI_MAC_BRIDGE_PORT_WAN_IFC){
		/* wan interface port status*/
		portState = OMCI_MAC_BRIDGE_PORT_STATE_6;//stp_off
	}else{
		ret = -1;
		goto end;
	}

	if(ret != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]-> ret !=0, fail!\n",__FUNCTION__,__LINE__);
		portState = OMCI_MAC_BRIDGE_PORT_STATE_6;
	}
	mac_br_dest_attr->portState = portState;
	
end:
	return ret;
}

#ifdef TCSUPPORT_PON_MAC_FILTER
/*******************************************************************************************************************************
9.3.6 mac bridge port filter table 

********************************************************************************************************************************/

/*******************************************************************************************
**function name
	getMacFilterRulePortIdByInst
**description:
	get mac filter rule port id
 **retrun :
 	-1:	failure
 	0:	success
**parameter:
  	instId :	9.3.4 instance id
  	macFilterRulePortId: return vlan rule port id
********************************************************************************************/
static int getMacFilterRulePortIdByInst(uint16_t instId, uint8_t * macFilterRulePortId){
	int ret = -1;
	int ifaceType = 0;
	uint8_t portId = 0;
	uint8_t portBasic = 0;
	uint8_t ifcType = 0;

	if(macFilterRulePortId == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n getMacFilterRulePortIdByInst-> parameter is NULL, fail");
		ret = -1;
		goto end;
	}
	
	/*get interface type*/
	ifaceType = getMacBridgePortInstType(instId,&ifcType);
	
	/*get ANI/UNI port id*/
	if(ifaceType == OMCI_MAC_BRIDGE_PORT_LAN_IFC){//lan, UNI port
		ret = getMacBridgeLanPortId(instId, &portId);
		if(ret != 0){
			ret = -1;
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n getMacFilterRulePortIdByInst-> not find lan port, fail");
			goto end;
		}
		portBasic = OMCI_MAC_BRIDGE_FILTER_LAN_PORT_BASIC;
	}else if(ifaceType == OMCI_MAC_BRIDGE_PORT_WAN_IFC){//wan , ANI port
		ret = getMacBridgeWanPortId(instId, &portId);
		if(ret != 0){
			ret = -1;
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n getMacFilterRulePortIdByInst-> not find wan port, fail");
			goto end;
		}
		portBasic = OMCI_MAC_BRIDGE_FILTER_WAN_PORT_BASIC;
	}else{
		ret = -1;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n getMacFilterRulePortIdByInst-> getMacBridgePortInstType, fail");
		goto end;
	}
	*macFilterRulePortId = portBasic +portId;
	
	ret = 0;
end:
	return ret;
}

/*******************************************************************************************
**function name
	findMacFilterRuleByRuleInfo
**description:
	find mac filter Rule by mac filter rule information
 **retrun :
 	-1:	not find
 	other:	return find rule index(0~xx)
**parameter:
	macFilterRule_ptr:	mac filter rule
  	macFilterRulePortId :	vlan rule port Id
  	macFilterType: 0:9.3.6, 1:9.3.7
********************************************************************************************/
static int findMacFilterRuleByRuleInfo(IN pon_mac_filter_rule_p macFilterRule_ptr, IN uint8_t macFilterRulePortId,  IN uint8_t macFilterType){
	int findFlag = -1;
	pon_mac_filter_rule_p portMacFilterRule_ptr = NULL;
	pon_mac_filter_rule_p currMacFilterRule_ptr = NULL;
	int currMaxNum = 0;
	int i = 0;
	uint8_t entryLen = 0;

	entryLen = sizeof(pon_mac_filter_rule);
	/*calloc space for saving mac filter rule in this port*/
	portMacFilterRule_ptr = (pon_mac_filter_rule_p)calloc(MAX_OMCI_MAC_FILTER_RULE_ONE_PORT , entryLen);
	if(portMacFilterRule_ptr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n findMacFilterRuleByRuleInfo-> calloc, fail");
		findFlag = -1;
		goto end;
	}
	/*get all mac filter rule in this port*/
	currMaxNum = pon_get_mac_filter_rule(macFilterRulePortId,macFilterType, portMacFilterRule_ptr);
	if(currMaxNum == -1){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n findMacFilterRuleByRuleInfo-> pon_get_mac_filter_rule, fail");
		findFlag = -1;
		goto end;
	}
	if(currMaxNum == 0){
		findFlag = -1;
		goto end;
	}
	/*find mac filter rule*/
	currMacFilterRule_ptr = portMacFilterRule_ptr;
	for(i=0; i<currMaxNum; i++){
		if(memcmp(currMacFilterRule_ptr, macFilterRule_ptr, entryLen) == 0){//find
			findFlag = i;
			break;
		}
		currMacFilterRule_ptr++;
	}
	
end:
	if(portMacFilterRule_ptr != NULL){
		free(portMacFilterRule_ptr);
		portMacFilterRule_ptr = NULL;
	}

	return findFlag;
}
#endif


int getMBPFTmacFilterTableValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	/*Do nothing in OMCI2.0*/
	return 0;	
}


int setMBPFTmacFilterTableValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
#ifdef TCSUPPORT_PON_MAC_FILTER
	int ret = -1;
	uint8_t *tmp_ptr = NULL;
	uint8_t index = 0;//record index in table
	/*  	filterType: 
  		Bit 	Name			Setting
  		1	filter/forward		0:forward,1:filter
  		2					0:dest mac, 1:src mac
  		3~6	reserved
  		7~8	add/remove		00:remove this entry, 01:addthis entry, 10:clear entire table
  	*/	
	uint8_t filterType = 0;
	uint8_t tempFilterType = 0;
	uint8_t mac[6] = {0};
	uint8_t action = 0;//0:remove this entry, 2:add this entry, 1: clear table
	uint16_t instanceId = 0;//instance id
	uint32_t tableSize = 0;
	uint32_t length = 0;
	uint8_t findFlag = OMCI_NO_FIND_RULE;//0:not find, 1:find
	pon_mac_filter_rule macFilterRule;
	pon_mac_filter_rule_p macFilterRule_ptr = NULL;
	uint8_t tempU8 = 0;
	uint8_t macFilterRulePortId= 0;
	int delIndex = 0;
	uint8_t tableFilterType = OMCI_MAC_BRIDGE_PORT_MAC_FILTER_TBL_TYPE_DEFAULT;
	omci_mac_br_port_filter_ptr mac_br_port_filter_attr = NULL;
	char * value = NULL;
	omci_me_info_t old_me = {0};
	omci_mac_br_port_filter_ptr mac_br_port_filter_old = NULL;

	
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	
	macFilterRule_ptr = &macFilterRule;
	memset(macFilterRule_ptr, 0, sizeof(pon_mac_filter_rule));
	
	/*get instance id*/
	instanceId = me_info->inst_id;

	/*get mac filter rule port id*/
	ret = getMacFilterRulePortIdByInst(instanceId, &macFilterRulePortId);
	if(ret != 0){
		ret = 0;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]-> getMacFilterRulePortIdByInst, not find mac filter rule port id\n",__FUNCTION__,__LINE__);
		goto end;
	}	
	
	mac_br_port_filter_attr = (omci_mac_br_port_filter_ptr)me_info->attributes;
    if(mac_br_port_filter_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	/*parse value*/	
	value = mac_br_port_filter_attr->macFilterOp.buf;
    if(value == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] Table attribute is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	
	index = *(uint8_t*)value;
	filterType = *(uint8_t *)(value+1);
	memcpy(mac, (uint8_t *)(value+2), 6);
	
	
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]>index=0x%2x,filterType=0x%02x,mac[0]=0x%02x,mac[1]=0x%02x,mac[2]=0x%02x,mac[3]=0x%02x,mac[4]=0x%02x,mac[5]=0x%02x\n",
		__FUNCTION__,__LINE__, index, filterType, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);

	/*get action(add/del/clear)*/
	action = (filterType >> 6);
	if((action != OMCI_MAC_BRIDGE_PORT_MAC_FILTER_DEL_ENTRY)
		&& (action != OMCI_MAC_BRIDGE_PORT_MAC_FILTER_ADD_ENTRY)
		&& (action != OMCI_MAC_BRIDGE_PORT_MAC_FILTER_CLEAR_ENTRY)){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]->action = %d, fail\n",__FUNCTION__,__LINE__, action);
		ret = -1;
		goto end;
	}
	if((action == OMCI_MAC_BRIDGE_PORT_MAC_FILTER_DEL_ENTRY) 
		|| (action ==OMCI_MAC_BRIDGE_PORT_MAC_FILTER_ADD_ENTRY)){// del or add
		
		old_me.class_id = me_info->class_id;
		old_me.inst_id = me_info->inst_id;
		old_me.mask = 0x8000;
		
		if(omci_attr_get_one_table_attr_by_mask(&old_me) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
			ret = -1;
			goto end;
		}		
		/*get current setting table entry. */
		mac_br_port_filter_old = (omci_mac_br_port_filter_ptr)old_me.attributes;  
		if(mac_br_port_filter_old == NULL){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
			ret = -1;
			goto end;
		}
		/*get current table content*/
		tableSize = mac_br_port_filter_old->macFilterOp.len;
		tmp_ptr = (uint8_t *)mac_br_port_filter_old->macFilterOp.buf;
		
		/*1.search record*/
		length = MAC_FILTER_RECORD_LENGTH;
		findFlag = OMCI_NO_FIND_RULE;
		while(tmp_ptr != NULL){
			if(index == *tmp_ptr){
				findFlag = OMCI_FIND_RULE;//find
				
				/*get mac filter rule information*/
				tempU8 = *(tmp_ptr+1); //filter type				
				memset(macFilterRule_ptr, 0, sizeof(macFilterRule));
				macFilterRule_ptr->filter_type = (tempU8&0x01);
				if((tempU8&0x02) == 0x02){
					macFilterRule_ptr->mac_type = OMCI_MAC_FILTER_RULE_MAC_TYPE_SRC;
				}else{
					macFilterRule_ptr->mac_type = OMCI_MAC_FILTER_RULE_MAC_TYPE_DST;
				}
				macFilterRule_ptr->ethertype = OMCI_MAC_FILTER_RULE_ETHERTYPE_0;
				memcpy(macFilterRule_ptr->start_mac, (tmp_ptr+2), 6);
				memcpy(macFilterRule_ptr->end_mac, (tmp_ptr+2), 6);
				
				break;
			}
			length += MAC_FILTER_RECORD_LENGTH;
			if(length > mac_br_port_filter_old->macFilterOp.len){//no find
				omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]->length > tableConent_ptr->tableSize\n",__FUNCTION__,__LINE__);
				break;
			}
			tmp_ptr += MAC_FILTER_RECORD_LENGTH;
		}
		/*get real length*/
		length -= MAC_FILTER_RECORD_LENGTH;
		
		/*2. get valid content in table, del find mac filter rule*/
		if(findFlag == OMCI_FIND_RULE){
			/*real delete a rule by MAC filter API*/
			delIndex = findMacFilterRuleByRuleInfo(macFilterRule_ptr, macFilterRulePortId, OMCI_MAC_FILTER_TYPE);
			if(delIndex != -1){//find
				ret = pon_del_mac_filter_rule(macFilterRulePortId,OMCI_MAC_FILTER_TYPE, delIndex);
				if(ret != 0){
					omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]->pon_del_mac_filter_rule ,failure\n",__FUNCTION__,__LINE__);
				}
			}
			
			/*if find, then delete this record in  table(instance)*/			
			tableSize -= MAC_FILTER_RECORD_LENGTH; //update current table size			
		}else{
			if(action == OMCI_MAC_BRIDGE_PORT_MAC_FILTER_DEL_ENTRY){//when delete entry, if this entry is not find, then return -1
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]->delete record and no find ,so failure\n",__FUNCTION__,__LINE__);
				ret = -1;
				goto end;
			}			
		}

		/*3.execute real add action*/		
		if(action == OMCI_MAC_BRIDGE_PORT_MAC_FILTER_ADD_ENTRY){//add new entry to this table 
			/*support max table size is 17 entry*/
			if(tableSize >= (MAX_OMCI_MAC_FILTER_9_3_6_RULE_ONE_PORT *MAC_FILTER_RECORD_LENGTH)){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]->tablesize = %d, overflow, fail\n",__FUNCTION__,__LINE__, tableSize);
				ret = -1;
				goto end;
			}
			/*real add a rule by MAC filter API*/
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]->add new entry!\n",__FUNCTION__,__LINE__);

			/*get mac filter rule information*/			
			memset(macFilterRule_ptr, 0, sizeof(macFilterRule));
			macFilterRule_ptr->filter_type = (filterType&0x01);
			if((filterType&0x02) == 0x02){
				macFilterRule_ptr->mac_type = OMCI_MAC_FILTER_RULE_MAC_TYPE_SRC;
			}else{
				macFilterRule_ptr->mac_type = OMCI_MAC_FILTER_RULE_MAC_TYPE_DST;
			}
			macFilterRule_ptr->ethertype = OMCI_MAC_FILTER_RULE_ETHERTYPE_0;
			memcpy(macFilterRule_ptr->start_mac, mac, 6);
			memcpy(macFilterRule_ptr->end_mac, mac, 6);

			/*get current table filter type*/
			if(tableSize == 0){
				tableFilterType = OMCI_MAC_BRIDGE_PORT_MAC_FILTER_TBL_TYPE_DEFAULT;
			}else{
				tempFilterType = *(mac_br_port_filter_old->macFilterOp.buf + 1);
				tableFilterType = (tempFilterType & 0x01);
			}

			if((tableFilterType != OMCI_MAC_BRIDGE_PORT_MAC_FILTER_TBL_TYPE_DEFAULT)
				&& (macFilterRule_ptr->filter_type != tableFilterType)){//It is not allow when forward and filter actions are mixed.
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n setMBPFTmacFilterTableValue->It is not allow when forward and filter actions are mixed, fail");
				ret = -1;
				goto end;	
			}
			/*add mac filter rule*/			
			ret = pon_add_mac_filter_rule(macFilterRulePortId,OMCI_MAC_FILTER_TYPE, macFilterRule_ptr);
			if(ret != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n setMBPFTmacFilterTableValue->pon_add_mac_filter_rule, fail");
				ret = -1;
				goto end;	
			}
			
			/*add entry to instance*/
			tableSize += MAC_FILTER_RECORD_LENGTH;
		}else{
			//nothing
		}
		
#if 0 //don't need in OMCI2.0
		/*5. update table content in instance table list*/
		if(tableConent_ptr != NULL){//del table content  in instance table list
			ret = omciDelTableValueOfInst(tmpomciMeInst_ptr, me_p->omciAttriDescriptList[1].attriIndex);
			if(ret != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n setMBPFTmacFilterTableValue->omciDelTableValueOfInst failure");
				ret = -1;
				goto end;
			}
		}
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n setMBPFTmacFilterTableValue->tableSize = %d",tableSize);
		
		if(tableSize == 0){//current table is empty
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n setMBPFTmacFilterTableValue->current table is empty");
			ret = 0;
			goto end;
		}
		tableConent_ptr = omciAddTableValueToInst(tmpomciMeInst_ptr, me_p->omciAttriDescriptList[1].attriIndex, tableSize, tmpValue_ptr);
		if(tableConent_ptr == NULL){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n setMBPFTmacFilterTableValue->omciAddTableValueToInst failure");
			ret = -1;
			goto end;	
		}
#endif		
	}else if(action == OMCI_MAC_BRIDGE_PORT_MAC_FILTER_CLEAR_ENTRY){//clear this table
#if 0 //don't need in OMCI2.0
		/*1. get table content*/
		tableConent_ptr = omciGetTableValueByIndex(tmpomciMeInst_ptr, me_p->omciAttriDescriptList[1].attriIndex);
		if(tableConent_ptr == NULL){
			ret = 0;
			goto end;	
		}
		tmp_ptr = tableConent_ptr->tableValue_p;
#endif
		/*2. real clean record*/
			/*clean all mac filter rule for this port*/	
		ret = pon_clean_mac_filter_rule(macFilterRulePortId, OMCI_MAC_FILTER_TYPE);	
		if(ret != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]-> pon_clean_mac_filter_rule, fail\n",__FUNCTION__,__LINE__);
			ret = -1;
			goto end;
		}
#if 0
		/*add 9.3.7 mac filter rule to this port*/	
		ret = addMacFilterRuleByInst(OMCI_CLASS_ID_MAC_BRIDGE_PORT_FILTER_PREASSIGN_DATA, instanceId, macFilterRulePortId);
		if(ret != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n omciMACBridgePortFilterDeleteAction-> addMacFilterRuleByMacFilterPortId, fail");
		}
#endif
#if 0 //don't need in OMCI2.0
		/*3.clean table in table list*/
		ret = omciDelTableValueOfInst(tmpomciMeInst_ptr, me_p->omciAttriDescriptList[1].attriIndex);
		if(ret != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n setMBPFTmacFilterTableValue->omciDelTableValueOfInst failure");
			ret = -1;
			goto end;
		}
#endif
		
	}
	ret = 0;
end:
	return ret;
#else
	return 0;
#endif
}


int omci_mac_br_port_filter_delete_op(management_entry_ptr me_entry, omci_me_info_ptr me_info){
#ifdef TCSUPPORT_PON_MAC_FILTER
	int ret = -1;
	uint16_t instId = 0;
	uint8_t macFilterRulePortId = 0;

    if((NULL == me_entry)||(NULL == me_info)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	
	/*get instance id*/	
	instId = me_info->inst_id;

	/*1.get mac filter rule port id*/
	ret = getMacFilterRulePortIdByInst(instId, &macFilterRulePortId);
	if(ret != 0){
		ret = 0;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]-> getMacFilterRulePortIdByInst, not find mac filter rule port id\n",__FUNCTION__,__LINE__);
		goto end;
	}
	
	/*2. clean all mac filter rule for this port*/	
	ret = pon_clean_mac_filter_rule(macFilterRulePortId, OMCI_MAC_FILTER_TYPE);	
	if(ret != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]-> pon_clean_mac_filter_rule, fail\n",__FUNCTION__,__LINE__);
	}

	ret = 0;
end:
	return ret;
#else
	return 0;
#endif
}

/*******************************************************************************************************************************
9.3.7 mac bridge port filter preassign table

********************************************************************************************************************************/

static int setMBPFPTFilterValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr, uint8_t type){
#ifdef TCSUPPORT_PON_MAC_FILTER
	int ret = -1;
	uint8_t val= 0;
	uint16_t instanceId = 0;
	pon_mac_filter_rule macFilterRule[MAX_OMCI_MAC_BRIDGE_FILTER_SIMULTANEOUS_RULE_NUM];
	pon_mac_filter_rule_p macFilterRule_ptr[MAX_OMCI_MAC_BRIDGE_FILTER_SIMULTANEOUS_RULE_NUM] = {NULL, NULL, NULL, NULL};
	uint8_t validRuleNum = 0;
	uint8_t macFilterRulePortId = 0;
	int delIndex = -1;
	int i = 0;
	uint8_t entryNum = 0;
	omci_mac_br_port_filter_pre_ptr mac_br_filter_pre_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	mac_br_filter_pre_attr = (omci_mac_br_port_filter_pre_ptr)me_info->attributes;
    if(mac_br_filter_pre_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

	/*init*/
	entryNum = sizeof(pon_mac_filter_rule);
	for(i = 0; i<MAX_OMCI_MAC_BRIDGE_FILTER_SIMULTANEOUS_RULE_NUM; i++){
		macFilterRule_ptr[i] = &macFilterRule[i];
		memset(macFilterRule_ptr[i], 0, entryNum);
		macFilterRule_ptr[i]->filter_type = OMCI_MAC_FILTER_RULE_TYPE_DISCARD;
		macFilterRule_ptr[i]->mac_type = OMCI_MAC_FILTER_RULE_MAC_TYPE_DST;		
	}
	
	/*get instance id*/
	instanceId = me_info->inst_id;
	
	/*1.get mac filter rule port id*/
	ret = getMacFilterRulePortIdByInst(instanceId, &macFilterRulePortId);
	if(ret != 0){
		ret = 0;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n setMBPFPTFilterValue-> getMacFilterRulePortIdByInst, not find mac filter rule port id, type = %d",type);
		goto end;
	}
	/*2.get mac filter rule information*/
	switch(type){
		case MAC_FILTER_IPV4_MULTICAST:	
			val = mac_br_filter_pre_attr->ipv4MultiFilter;
			macFilterRule_ptr[0]->ethertype = OMCI_MAC_FILTER_RULE_ETHERTYPE_0;
			macFilterRule_ptr[0]->start_mac[0] = 0x01;
			macFilterRule_ptr[0]->start_mac[1] = 0x00;
			macFilterRule_ptr[0]->start_mac[2] = 0x5e;
			macFilterRule_ptr[0]->start_mac[3] = 0x00;
			macFilterRule_ptr[0]->start_mac[4] = 0x00;
			macFilterRule_ptr[0]->start_mac[5] = 0x00;

			macFilterRule_ptr[0]->end_mac[0] = 0x01;
			macFilterRule_ptr[0]->end_mac[1] = 0x00;
			macFilterRule_ptr[0]->end_mac[2] = 0x5e;
			macFilterRule_ptr[0]->end_mac[3] = 0x7f;
			macFilterRule_ptr[0]->end_mac[4] = 0xff;
			macFilterRule_ptr[0]->end_mac[5] = 0xff;
			validRuleNum = 1;
			break;
		case MAC_FILTER_IPV6_MULTICAST:
			val = mac_br_filter_pre_attr->ipv6MultiFilter;
			macFilterRule_ptr[0]->ethertype = OMCI_MAC_FILTER_RULE_ETHERTYPE_0;
			macFilterRule_ptr[0]->start_mac[0] = 0x33;
			macFilterRule_ptr[0]->start_mac[1] = 0x33;
			macFilterRule_ptr[0]->start_mac[2] = 0x00;
			macFilterRule_ptr[0]->start_mac[3] = 0x00;
			macFilterRule_ptr[0]->start_mac[4] = 0x00;
			macFilterRule_ptr[0]->start_mac[5] = 0x00;

			macFilterRule_ptr[0]->end_mac[0] = 0x33;
			macFilterRule_ptr[0]->end_mac[1] = 0x33;
			macFilterRule_ptr[0]->end_mac[2] = 0xff;
			macFilterRule_ptr[0]->end_mac[3] = 0xff;
			macFilterRule_ptr[0]->end_mac[4] = 0xff;
			macFilterRule_ptr[0]->end_mac[5] = 0xff;
			validRuleNum = 1;
			break;
		case MAC_FILTER_IPV4_BROADCAST:
			val = mac_br_filter_pre_attr->ipv4BroadFilter;
			macFilterRule_ptr[0]->ethertype = OMCI_MAC_FILTER_RULE_ETHERTYPE_0800;
			macFilterRule_ptr[0]->start_mac[0] = 0xff;
			macFilterRule_ptr[0]->start_mac[1] = 0xff;
			macFilterRule_ptr[0]->start_mac[2] = 0xff;
			macFilterRule_ptr[0]->start_mac[3] = 0xff;
			macFilterRule_ptr[0]->start_mac[4] = 0xff;
			macFilterRule_ptr[0]->start_mac[5] = 0xff;

			macFilterRule_ptr[0]->end_mac[0] = 0xff;
			macFilterRule_ptr[0]->end_mac[1] = 0xff;
			macFilterRule_ptr[0]->end_mac[2] = 0xff;
			macFilterRule_ptr[0]->end_mac[3] = 0xff;
			macFilterRule_ptr[0]->end_mac[4] = 0xff;
			macFilterRule_ptr[0]->end_mac[5] = 0xff;
			validRuleNum = 1;
			break;
		case MAC_FILTER_RARP:
			val = mac_br_filter_pre_attr->rarpFilter;
			macFilterRule_ptr[0]->ethertype = OMCI_MAC_FILTER_RULE_ETHERTYPE_8035;
			macFilterRule_ptr[0]->start_mac[0] = 0xff;
			macFilterRule_ptr[0]->start_mac[1] = 0xff;
			macFilterRule_ptr[0]->start_mac[2] = 0xff;
			macFilterRule_ptr[0]->start_mac[3] = 0xff;
			macFilterRule_ptr[0]->start_mac[4] = 0xff;
			macFilterRule_ptr[0]->start_mac[5] = 0xff;

			macFilterRule_ptr[0]->end_mac[0] = 0xff;
			macFilterRule_ptr[0]->end_mac[1] = 0xff;
			macFilterRule_ptr[0]->end_mac[2] = 0xff;
			macFilterRule_ptr[0]->end_mac[3] = 0xff;
			macFilterRule_ptr[0]->end_mac[4] = 0xff;
			macFilterRule_ptr[0]->end_mac[5] = 0xff;
			validRuleNum = 1;
			break;
		case MAC_FILTER_IPX:
			/*first*/
			val = mac_br_filter_pre_attr->ipxFilter;
			macFilterRule_ptr[0]->ethertype = OMCI_MAC_FILTER_RULE_ETHERTYPE_8137;
			macFilterRule_ptr[0]->start_mac[0] = 0xff;
			macFilterRule_ptr[0]->start_mac[1] = 0xff;
			macFilterRule_ptr[0]->start_mac[2] = 0xff;
			macFilterRule_ptr[0]->start_mac[3] = 0xff;
			macFilterRule_ptr[0]->start_mac[4] = 0xff;
			macFilterRule_ptr[0]->start_mac[5] = 0xff;

			macFilterRule_ptr[0]->end_mac[0] = 0xff;
			macFilterRule_ptr[0]->end_mac[1] = 0xff;
			macFilterRule_ptr[0]->end_mac[2] = 0xff;
			macFilterRule_ptr[0]->end_mac[3] = 0xff;
			macFilterRule_ptr[0]->end_mac[4] = 0xff;
			macFilterRule_ptr[0]->end_mac[5] = 0xff;
			/*second*/
			macFilterRule_ptr[1]->ethertype = OMCI_MAC_FILTER_RULE_ETHERTYPE_0;
			macFilterRule_ptr[1]->start_mac[0] = 0x09;
			macFilterRule_ptr[1]->start_mac[1] = 0x00;
			macFilterRule_ptr[1]->start_mac[2] = 0x1b;
			macFilterRule_ptr[1]->start_mac[3] = 0xff;
			macFilterRule_ptr[1]->start_mac[4] = 0xff;
			macFilterRule_ptr[1]->start_mac[5] = 0xff;

			macFilterRule_ptr[1]->end_mac[0] = 0x09;
			macFilterRule_ptr[1]->end_mac[1] = 0x00;
			macFilterRule_ptr[1]->end_mac[2] = 0x1b;
			macFilterRule_ptr[1]->end_mac[3] = 0xff;
			macFilterRule_ptr[1]->end_mac[4] = 0xff;
			macFilterRule_ptr[1]->end_mac[5] = 0xff;			
			/*third*/
			macFilterRule_ptr[2]->ethertype = OMCI_MAC_FILTER_RULE_ETHERTYPE_0;
			macFilterRule_ptr[2]->start_mac[0] = 0x09;
			macFilterRule_ptr[2]->start_mac[1] = 0x00;
			macFilterRule_ptr[2]->start_mac[2] = 0x4e;
			macFilterRule_ptr[2]->start_mac[3] = 0x00;
			macFilterRule_ptr[2]->start_mac[4] = 0x00;
			macFilterRule_ptr[2]->start_mac[5] = 0x02;

			macFilterRule_ptr[2]->end_mac[0] = 0x09;
			macFilterRule_ptr[2]->end_mac[1] = 0x00;
			macFilterRule_ptr[2]->end_mac[2] = 0x4e;
			macFilterRule_ptr[2]->end_mac[3] = 0x00;
			macFilterRule_ptr[2]->end_mac[4] = 0x00;
			macFilterRule_ptr[2]->end_mac[5] = 0x02;
			validRuleNum = 3;
			break;
		case MAC_FILTER_NETBEUL:
			val = mac_br_filter_pre_attr->netBeuiFilter;
			macFilterRule_ptr[0]->ethertype = OMCI_MAC_FILTER_RULE_ETHERTYPE_0;
			macFilterRule_ptr[0]->start_mac[0] = 0x03;
			macFilterRule_ptr[0]->start_mac[1] = 0x00;
			macFilterRule_ptr[0]->start_mac[2] = 0x00;
			macFilterRule_ptr[0]->start_mac[3] = 0x00;
			macFilterRule_ptr[0]->start_mac[4] = 0x00;
			macFilterRule_ptr[0]->start_mac[5] = 0x01;

			macFilterRule_ptr[0]->end_mac[0] = 0x03;
			macFilterRule_ptr[0]->end_mac[1] = 0x00;
			macFilterRule_ptr[0]->end_mac[2] = 0x00;
			macFilterRule_ptr[0]->end_mac[3] = 0x00;
			macFilterRule_ptr[0]->end_mac[4] = 0x00;
			macFilterRule_ptr[0]->end_mac[5] = 0x01;
			validRuleNum = 1;
			break;
		case MAC_FILTER_AARP:
			val = mac_br_filter_pre_attr->appleTalkFilter;
			/*first*/
			macFilterRule_ptr[0]->ethertype = OMCI_MAC_FILTER_RULE_ETHERTYPE_809b;
			macFilterRule_ptr[0]->start_mac[0] = 0xff;
			macFilterRule_ptr[0]->start_mac[1] = 0xff;
			macFilterRule_ptr[0]->start_mac[2] = 0xff;
			macFilterRule_ptr[0]->start_mac[3] = 0xff;
			macFilterRule_ptr[0]->start_mac[4] = 0xff;
			macFilterRule_ptr[0]->start_mac[5] = 0xff;

			macFilterRule_ptr[0]->end_mac[0] = 0xff;
			macFilterRule_ptr[0]->end_mac[1] = 0xff;
			macFilterRule_ptr[0]->end_mac[2] = 0xff;
			macFilterRule_ptr[0]->end_mac[3] = 0xff;
			macFilterRule_ptr[0]->end_mac[4] = 0xff;
			macFilterRule_ptr[0]->end_mac[5] = 0xff;
			/*second*/
			macFilterRule_ptr[1]->ethertype = OMCI_MAC_FILTER_RULE_ETHERTYPE_80f3;
			macFilterRule_ptr[1]->start_mac[0] = 0xff;
			macFilterRule_ptr[1]->start_mac[1] = 0xff;
			macFilterRule_ptr[1]->start_mac[2] = 0xff;
			macFilterRule_ptr[1]->start_mac[3] = 0xff;
			macFilterRule_ptr[1]->start_mac[4] = 0xff;
			macFilterRule_ptr[1]->start_mac[5] = 0xff;

			macFilterRule_ptr[1]->end_mac[0] = 0xff;
			macFilterRule_ptr[1]->end_mac[1] = 0xff;
			macFilterRule_ptr[1]->end_mac[2] = 0xff;
			macFilterRule_ptr[1]->end_mac[3] = 0xff;
			macFilterRule_ptr[1]->end_mac[4] = 0xff;
			macFilterRule_ptr[1]->end_mac[5] = 0xff;			
			/*third*/
			macFilterRule_ptr[2]->ethertype = OMCI_MAC_FILTER_RULE_ETHERTYPE_0;
			macFilterRule_ptr[2]->start_mac[0] = 0x09;
			macFilterRule_ptr[2]->start_mac[1] = 0x00;
			macFilterRule_ptr[2]->start_mac[2] = 0x07;
			macFilterRule_ptr[2]->start_mac[3] = 0x00;
			macFilterRule_ptr[2]->start_mac[4] = 0x00;
			macFilterRule_ptr[2]->start_mac[5] = 0x00;

			macFilterRule_ptr[2]->end_mac[0] = 0x09;
			macFilterRule_ptr[2]->end_mac[1] = 0x00;
			macFilterRule_ptr[2]->end_mac[2] = 0x07;
			macFilterRule_ptr[2]->end_mac[3] = 0x00;
			macFilterRule_ptr[2]->end_mac[4] = 0x00;
			macFilterRule_ptr[2]->end_mac[5] = 0xfc;
			/*fourth*/
			macFilterRule_ptr[3]->ethertype = OMCI_MAC_FILTER_RULE_ETHERTYPE_0;
			macFilterRule_ptr[3]->start_mac[0] = 0x09;
			macFilterRule_ptr[3]->start_mac[1] = 0x00;
			macFilterRule_ptr[3]->start_mac[2] = 0x07;
			macFilterRule_ptr[3]->start_mac[3] = 0xff;
			macFilterRule_ptr[3]->start_mac[4] = 0xff;
			macFilterRule_ptr[3]->start_mac[5] = 0xff;

			macFilterRule_ptr[3]->end_mac[0] = 0x09;
			macFilterRule_ptr[3]->end_mac[1] = 0x00;
			macFilterRule_ptr[3]->end_mac[2] = 0x07;
			macFilterRule_ptr[3]->end_mac[3] = 0xff;
			macFilterRule_ptr[3]->end_mac[4] = 0xff;
			macFilterRule_ptr[3]->end_mac[5] = 0xff;
			validRuleNum = 4;
			break;
		case MAC_FILTER_MANAGE_INFO:
			val = mac_br_filter_pre_attr->brMngInfoFilter;
			macFilterRule_ptr[0]->ethertype = OMCI_MAC_FILTER_RULE_ETHERTYPE_0;
			macFilterRule_ptr[0]->start_mac[0] = 0x01;
			macFilterRule_ptr[0]->start_mac[1] = 0x80;
			macFilterRule_ptr[0]->start_mac[2] = 0xc2;
			macFilterRule_ptr[0]->start_mac[3] = 0x00;
			macFilterRule_ptr[0]->start_mac[4] = 0x00;
			macFilterRule_ptr[0]->start_mac[5] = 0x00;

			macFilterRule_ptr[0]->end_mac[0] = 0x01;
			macFilterRule_ptr[0]->end_mac[1] = 0x80;
			macFilterRule_ptr[0]->end_mac[2] = 0xc2;
			macFilterRule_ptr[0]->end_mac[3] = 0x00;
			macFilterRule_ptr[0]->end_mac[4] = 0x00;
			macFilterRule_ptr[0]->end_mac[5] = 0xff;
			validRuleNum = 1;
			break;
		case MAC_FILTER_ARP:
			val = mac_br_filter_pre_attr->arpFilter;
			macFilterRule_ptr[0]->ethertype = OMCI_MAC_FILTER_RULE_ETHERTYPE_0806;
			macFilterRule_ptr[0]->start_mac[0] = 0xff;
			macFilterRule_ptr[0]->start_mac[1] = 0xff;
			macFilterRule_ptr[0]->start_mac[2] = 0xff;
			macFilterRule_ptr[0]->start_mac[3] = 0xff;
			macFilterRule_ptr[0]->start_mac[4] = 0xff;
			macFilterRule_ptr[0]->start_mac[5] = 0xff;

			macFilterRule_ptr[0]->end_mac[0] = 0xff;
			macFilterRule_ptr[0]->end_mac[1] = 0xff;
			macFilterRule_ptr[0]->end_mac[2] = 0xff;
			macFilterRule_ptr[0]->end_mac[3] = 0xff;
			macFilterRule_ptr[0]->end_mac[4] = 0xff;
			macFilterRule_ptr[0]->end_mac[5] = 0xff;
			validRuleNum = 1;
			break;
		case MAC_FILTER_PPPOE_BROADCAST:
			val = mac_br_filter_pre_attr->pppoeBroadFilter;
			macFilterRule_ptr[0]->ethertype = OMCI_MAC_FILTER_RULE_ETHERTYPE_8863;
			macFilterRule_ptr[0]->start_mac[0] = 0xff;
			macFilterRule_ptr[0]->start_mac[1] = 0xff;
			macFilterRule_ptr[0]->start_mac[2] = 0xff;
			macFilterRule_ptr[0]->start_mac[3] = 0xff;
			macFilterRule_ptr[0]->start_mac[4] = 0xff;
			macFilterRule_ptr[0]->start_mac[5] = 0xff;

			macFilterRule_ptr[0]->end_mac[0] = 0xff;
			macFilterRule_ptr[0]->end_mac[1] = 0xff;
			macFilterRule_ptr[0]->end_mac[2] = 0xff;
			macFilterRule_ptr[0]->end_mac[3] = 0xff;
			macFilterRule_ptr[0]->end_mac[4] = 0xff;
			macFilterRule_ptr[0]->end_mac[5] = 0xff;
			validRuleNum = 1;
			break;
		case MAC_FILTER_TABLE_ENTRY://don't support 9.3.6
		default:
			ret = -1;
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]-> type=%d, fail\n",__FUNCTION__,__LINE__, type);
			goto end;
	}
	
	if((val != 0) && (val != 1)){
		ret = -1;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]-> val = %d,type = %d,  fail\n",__FUNCTION__,__LINE__,val, type);
		goto end;
	}
	
	/*3. set mac filter rule*/
	for(i = 0; i<validRuleNum; i++){
		if(val == 0){ //del mac filter rule
			delIndex = findMacFilterRuleByRuleInfo(macFilterRule_ptr[i], macFilterRulePortId, OMCI_PKT_FILTER_TYPE);
			if(delIndex != -1){
				ret = pon_del_mac_filter_rule(macFilterRulePortId,OMCI_PKT_FILTER_TYPE, delIndex);
				if(ret != 0){
					omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]-> pon_del_mac_filter_rule,type=%d, i=%d, fail\n",__FUNCTION__,__LINE__, type, i);
				}
			}
			
		}else if(val == 1){ //add mac filter rule
			ret = pon_add_mac_filter_rule(macFilterRulePortId,OMCI_PKT_FILTER_TYPE, macFilterRule_ptr[i]);
			if(ret != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]-> pon_add_mac_filter_rule,type=%d, i=%d, fail\n",__FUNCTION__,__LINE__, type, i);
			}
		}else{
			//nothing
		}
	}
	
	ret = 0;
end:
	return ret;
#else
	return 0;
#endif
}

int setMBPFPTipv4MulticastFilterValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
	return setMBPFPTFilterValue(me_info,omci_attr,MAC_FILTER_IPV4_MULTICAST);
}

int setMBPFPTipv6MulticastFilterValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
	return setMBPFPTFilterValue(me_info,omci_attr,MAC_FILTER_IPV6_MULTICAST);
}
int setMBPFPTipv4BroadcastFilterValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
	return setMBPFPTFilterValue(me_info,omci_attr,MAC_FILTER_IPV4_BROADCAST);
}
int setMBPFPTRARPFilterValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
	return setMBPFPTFilterValue(me_info,omci_attr,MAC_FILTER_RARP);
}
int setMBPFPTIPXFilterValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
	return setMBPFPTFilterValue(me_info,omci_attr,MAC_FILTER_IPX);
}
int setMBPFPTNetBEULFilterValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
	return setMBPFPTFilterValue(me_info,omci_attr,MAC_FILTER_NETBEUL);
}
int setMBPFPTappleTalkFilterValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
	return setMBPFPTFilterValue(me_info,omci_attr,MAC_FILTER_AARP);
}
int setMBPFPTmanageInfoFilterValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
	return setMBPFPTFilterValue(me_info,omci_attr,MAC_FILTER_MANAGE_INFO);
}
int setMBPFPTARPFilterValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
	return setMBPFPTFilterValue(me_info,omci_attr,MAC_FILTER_ARP);
}
int setMBPFPTPPPoEBroadcastFilterValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
	return setMBPFPTFilterValue(me_info,omci_attr,MAC_FILTER_PPPOE_BROADCAST);
}


int omci_mac_br_port_filter_pre_delete_op(management_entry_ptr me_entry, omci_me_info_ptr me_info){
#ifdef TCSUPPORT_PON_MAC_FILTER
	int ret = -1;
	uint16_t instId = 0;
	uint8_t macFilterRulePortId = 0;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == me_entry)||(NULL == me_info)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	
	/*get instance id*/	
	instId = me_info->inst_id;

	/*1.get mac filter rule port id*/
	ret = getMacFilterRulePortIdByInst(instId, &macFilterRulePortId);
	if(ret != 0){
		ret = 0;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]-> getMacFilterRulePortIdByInst, not find mac filter rule port id\n",__FUNCTION__,__LINE__);
		goto end;
	}
	
	/*2. clean all mac filter rule for this port*/	
	ret = pon_clean_mac_filter_rule(macFilterRulePortId,OMCI_PKT_FILTER_TYPE);	
	if(ret != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]-> pon_clean_mac_filter_rule, fail\n",__FUNCTION__,__LINE__);
	}
#if 0
	/*3. add 9.3.6 mac filter rule to this port*/	
	ret = addMacFilterRuleByInst(OMCI_CLASS_ID_MAC_BRIDGE_PORT_FILTER_TABLE_DATA, instId, macFilterRulePortId);
	if(ret != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n omciMACBridgePortFilterPreDeleteAction-> addMacFilterRuleByMacFilterPortId, fail");
	}
#endif
	ret = 0;
end:
	return ret;
#else
	return 0;
#endif
}


/*******************************************************************************************************************************
9.3.8 mac bridge port bridge table data

********************************************************************************************************************************/


/*******************************************************************************************
**function name
	getMacBridgePortIfcByInst
**description:
	get mac bridge port interface name via  the instance id of MAC bridge port configuration data ME
 **retrun :
 	0:	success
 	-1:	failure
**parameter:
	instanceId: me instance id
  	ifcName: return interface name, eg:eth0.1
********************************************************************************************/
int getMacBridgePortIfcByInst(IN uint16_t instanceId, OUT char * ifcName){
	int ifaceType = 0; //0:UNI, 1:ANI	
	uint8_t portId = 0;//UNI/ANI port id
	int ret = -1;
	uint8_t ifcType = 0;

	if(ifcName == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]->parameter is error, failure\n",__FUNCTION__,__LINE__);
		return -1;			
	}	

	/*get interface type*/
	ifaceType = getMacBridgePortInstType(instanceId,&ifcType);
	/*only support getting bridge table information in UNI or ANI port*/
	if(ifaceType == OMCI_MAC_BRIDGE_PORT_LAN_IFC){//UNI port
		/*get lan  portid*/
     #if/*TCSUPPORT_COMPILE*/ defined(TCSUPPORT_CHS)
		if((pSystemCap->geNum + pSystemCap->feNum) <= 1){
			sprintf(ifcName, "eth0");
		}
		else{
     #endif/*TCSUPPORT_COMPILE*/
			ret = getMacBridgeLanPortId(instanceId, &portId);
			if(ret != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]->getMacBridgeLanPortId failure\n",__FUNCTION__,__LINE__);
				ret = -1;
				goto end;
			}
			if(ifcType == OMCI_MAC_BRIDGE_PORT_VEIP)
				sprintf(ifcName, "VEIP"); //VEIP
			else	
				sprintf(ifcName, "%s%d", OMCI_LAN_INTERFACE_PREFIX_STR, portId); //eth0.1~eth0.4
	 #if/*TCSUPPORT_COMPILE*/ defined(TCSUPPORT_CHS)
        }
     #endif/*TCSUPPORT_COMPILE*/
	}else if(ifaceType == OMCI_MAC_BRIDGE_PORT_WAN_IFC){//ANI port
		/*get Wan  portid*/
		ret = getMacBridgeWanPortId(instanceId, &portId);
		if(ret != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]->getMacBridgeWanPortId failure\n",__FUNCTION__,__LINE__);
			ret = -1;
			goto end;
		}
	}else{//no UNI/ANI port 
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]->ifaceType =%d failure\n",__FUNCTION__,__LINE__,ifaceType);
			ret = -1;
			goto end;
	}

	ret = 0;
	
end:
//	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]->ifaceType=%d\n",__FUNCTION__,__LINE__,ifaceType);
//	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]->portId=%d\n",__FUNCTION__,__LINE__,portId);
//	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]->ifcName=%s\n",__FUNCTION__,__LINE__,ifcName);	
	return ret;
}

/*******************************************************************************************
**function name
	findMacBridgeFirstStr
**description:
	find the first string in row buffer,
	find the remain buffer in row buffer.
 **retrun :
 	0:	success
 	-1:	failure
**parameter:
	rowBuf: row buffer
	fromLen: from rowBuf+fromLen
	firstStr: first words string
********************************************************************************************/

static int findMacBridgeFirstStr(char * rowBuf, uint32_t * fromLen, char * firstStr){
	char *rowPtr = NULL;	
	char buf[MAX_MAC_BRIDGE_RECORD_BUF] = {0};
	int len = 0;
	uint32_t currLen = 0;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
	if((rowBuf == NULL) || (firstStr == NULL)){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n findMacBridgeFirstStr  fail ");
		return -1;
	}
	memset(buf, 0, sizeof(buf));
	currLen = *fromLen;

//	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n findMacBridgeFirstStr->fromLen =%d",*fromLen);
	
	rowPtr = rowBuf+currLen;
	/*strip the prefix space*/
	while(*rowPtr != '\0'){
		if((*rowPtr != ' ') && (*rowPtr != '\t'))
			break;
		currLen++;
		rowPtr++;
	}
	/*get first Str*/
	len = 0;
	while(*rowPtr != '\0'){		
		if((*rowPtr == ' ') || (*rowPtr == '\t')){	
			break;
		}
		if(len >=  MAX_MAC_BRIDGE_RECORD_BUF){
			goto failure;
		}
		buf[len++] = *rowPtr;
		currLen++;
		rowPtr++;
	}
	buf[MAX_MAC_BRIDGE_RECORD_BUF-1] = '\0';
	strcpy(firstStr, buf);
//	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n findMacBridgeFirstStr->firstStr =%s",firstStr);
	* fromLen = currLen;
//	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n findMacBridgeFirstStr->currLen =%d",currLen);
	
	return 0;
failure:
//	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n findMacBridgeFirstStr->len =%d",len);

	return -1;

}

/*******************************************************************************************
**function name
	char2Hex
**description:
	convert character arr to HEX
 **retrun :
 	-1:	failure
 	other: hex value
**parameter:
  	arr: source character
********************************************************************************************/
static int char2Hex(char arr){
	uint8_t a;

	if(arr>='0' && arr <= '9')
		a = arr-'0';
	else if(arr>='a' && arr <= 'f')
		a = arr-'a'+10;
	else if(arr>='A' && arr <= 'F')
		a = arr-'A'+10;
	else 
		return -1;
	
	return a;
}


/*******************************************************************************************
**function name
	getMacFormMacStr
**description:
	get 6 bytes mac addres form mac string
 **retrun :
 	0:	success
 	-1:	failure
**parameter:
	delimiter: strip char
	macStr: mac string 
	mac: 6 bytes mac address
********************************************************************************************/
static int getMacFormMacStr(char delimiter, char * macStr, uint8_t * mac){
	char * tempPtr = NULL;
	uint8_t tempMac[OMCI_MAC_LENGTH] = {0};
	int8_t temp = 0;
	int i = 0;
	int k = 0;
	
	if((macStr == NULL) || (mac == NULL)){
		return -1;
	}
	if(strlen(macStr) != 17){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n getMacFormMacStr->macStr len = %lu error",strlen(macStr));
		return -1;
	}
	memset(tempMac, 0, sizeof(tempMac));
	
	tempPtr = macStr;
	
	while(*tempPtr != '\0'){
		if(*tempPtr != delimiter){
			temp = char2Hex(*tempPtr);
			if(temp == -1){
				return -1;
			}
			if((i%2) == 0){
				tempMac[k] = (temp<<4);
			}else{
				tempMac[k] |= temp;
				k++;
			}
			i++;
		}
		tempPtr++;
	}
	if(k == 0){
		return -1;
	}
	memcpy(mac, tempMac, 6);
	return 0;	
}


/*******************************************************************************************
**function name
	getSearchFilterMacFormFilterTbl
**description:
	find mac address in mac filter table(only filter type)
 **retrun :
 	0:	success
 	-1:	failure
**parameter:
	instanceId: instance id
	mac: find mac address
	find: return find result
********************************************************************************************/
static int getSearchFilterMacFormFilterTbl(IN uint16_t instanceId,IN  uint8_t *mac, OUT uint8_t *find, OUT uint8_t * filterFlag){
	uint8_t macStart[6] = {0};
	uint16_t length = 0;
	char *tmp_ptr = NULL;
	/*  	filterType: 
		Bit 	Name			Setting
		1	filter/forward		0:forward,1:filter
		2					0:dest mac, 1:src mac
		3~6	reserved
		7~8	add/remove		00:remove this entry, 01:addthis entry, 10:clear entire table
  	*/	
	uint8_t filterType = 0;
	int ret = 0;
	omci_me_info_t me_info = {0};
	omci_mac_br_port_br_tbl_ptr mac_br_port_tbl_attr = NULL;
	omci_me_info_t old_me = {0};
	omci_mac_br_port_filter_pre_ptr mac_br_port_filter_pre_old = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
	if(mac == NULL || find == NULL ||filterFlag == NULL ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n getSearchFilterMacFormFilterTbl->parameter NULL, fail");
		return -1;
	}

	/*find mac filter in  9.3.6 mac filter table*/

	me_info.class_id = OMCI_CLASS_ID_MAC_BRIDGE_PORT_FILTER_TABLE_DATA;
	me_info.inst_id = instanceId;
	me_info.mask = (0x8000);
	if(omci_attr_get_one_table_attr_by_mask(&me_info) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}
	mac_br_port_tbl_attr = (omci_mac_br_port_br_tbl_ptr)me_info.attributes;
	if(NULL == mac_br_port_tbl_attr){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->gem_interwork_tp_attr calloc fail\n",__FUNCTION__);
		ret = -1;
		goto end;
	}

	/*search record in 9.3.6 mac filter table*/
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]->search 9.3.6 start\n",__FUNCTION__,__LINE__);
	
	tmp_ptr = mac_br_port_tbl_attr->brTable.buf;
	length = MAC_FILTER_RECORD_LENGTH;
	while(tmp_ptr != NULL){
		tmp_ptr += 1;//jump index, get filter type
		filterType  = *tmp_ptr;
		tmp_ptr += 1;//jump filter type, get mac
		if(((filterType & MAC_FILTER_TYPE_80_VALID_BITS) == MAC_FILTER_TYPE_80)
			&& (memcmp(mac,tmp_ptr,OMCI_MAC_LENGTH) == 0)){
			*find = OMCI_FIND_RULE;//find
			*filterFlag = (filterType & 0x01);

			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n getSearchFilterMacFormFilterTbl->findFlag = %d, filterType =%d", *find, filterType);
			
			ret = 0;
			goto end;
		}
		length += MAC_FILTER_RECORD_LENGTH;
		if(length >= mac_br_port_tbl_attr->brTable.len){
			break;
		}
		tmp_ptr += OMCI_MAC_LENGTH;
	}
//	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n getSearchFilterMacFormFilterTbl->search 9.3.6 end");	
	/*find mac filter in  9.3.7 mac prefilter table*/
	old_me.class_id = OMCI_CLASS_ID_MAC_BRIDGE_PORT_FILTER_PREASSIGN_DATA;
	old_me.inst_id = instanceId;
	
	if(omci_attr_get_old_data_except_table_attr(&old_me) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}		
	/*get current setting table entry. */
	mac_br_port_filter_pre_old = (omci_mac_br_port_filter_pre_ptr)old_me.attributes;  
	if(mac_br_port_filter_pre_old == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}

	ret = 0;

	//MAC_FILTER_IPV4_MULTICAST://01.00.5e.00.00.00.00--01.00.5e.7f.ff.ff
	macStart[0] = 0x01;
	macStart[1] = 0x00;
	macStart[2] = 0x5e;
	if((memcmp(macStart, mac, 3) == 0)
		&&(mac[3]<=0x7f)){
		*find = OMCI_FIND_RULE;//find
		*filterFlag = mac_br_port_filter_pre_old->ipv4MultiFilter;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]:MAC_FILTER_IPV4_MULTICAST\n",__FUNCTION__,__LINE__);
		goto end;
	}

	//MAC_FILTER_IPV6_MULTICAST://33.33.00.00.00.00.00--33.33.ff.ff.ff.ff
	if((mac[0] == 0x33)
		&&(mac[1] == 0x33)){
		*find = OMCI_FIND_RULE;//find
		*filterFlag = mac_br_port_filter_pre_old->ipv6MultiFilter;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]:MAC_FILTER_IPV6_MULTICAST\n",__FUNCTION__,__LINE__);
		goto end;
	}						

	//MAC_FILTER_IPX:
	/*09:00:1b:ff:ff:ff*/
	macStart[0] = 0x09;
	macStart[1] = 0x0;
	macStart[2] = 0x1b;
	macStart[3] = 0xff;
	macStart[4] = 0xff;
	macStart[5] = 0xff;					
	if(memcmp(macStart, mac, 6) == 0){
		*find = OMCI_FIND_RULE;//find
		*filterFlag = mac_br_port_filter_pre_old->ipxFilter;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]:MAC_FILTER_IPX\n",__FUNCTION__,__LINE__);
		goto end;
	}

	/*09:00:4e:00:00:02*/
	macStart[0] = 0x09;
	macStart[1] = 0x0;
	macStart[2] = 0x4e;
	macStart[3] = 0x00;
	macStart[4] = 0x00;
	macStart[5] = 0x02;
	if(memcmp(macStart, mac, 6) == 0){
		*find = OMCI_FIND_RULE;//find
		*filterFlag = mac_br_port_filter_pre_old->ipxFilter;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]:MAC_FILTER_IPX\n",__FUNCTION__,__LINE__);
		goto end;
	}

	//MAC_FILTER_NETBEUL://0x03, 0x00, 0x00, 0x00, 0x00, 0x01
	macStart[0] = 0x03;
	macStart[1] = 0x0;
	macStart[2] = 0x0;
	macStart[3] = 0x0;
	macStart[4] = 0x0;
	macStart[5] = 0x01;
	if(memcmp(macStart, mac, 6) == 0){
		*find = OMCI_FIND_RULE;//find
		*filterFlag = mac_br_port_filter_pre_old->netBeuiFilter;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]:MAC_FILTER_NETBEUL\n",__FUNCTION__,__LINE__);
		goto end;
	}

	//MAC_FILTER_AARP://09:00:07:00:00:00~ 09:00:07:00:00:fc, 09:00:07:ff:ff:ff
	macStart[0] = 0x09;
	macStart[1] = 0x0;
	macStart[2] = 0x07;
	macStart[3] = 0x0;
	macStart[4] = 0x0;
	if((memcmp(macStart, mac, 5) == 0)
		&&(mac[5] <= 0xfc)){
		*find = OMCI_FIND_RULE;//find
		*filterFlag = mac_br_port_filter_pre_old->appleTalkFilter;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]:MAC_FILTER_AARP\n",__FUNCTION__,__LINE__);
		goto end;
	}
	macStart[0] = 0x09;
	macStart[1] = 0x0;
	macStart[2] = 0x07;
	macStart[3] = 0xff;
	macStart[4] = 0xff;
	macStart[5] = 0xff;
	if(memcmp(macStart, mac, 6) == 0){
		*find = OMCI_FIND_RULE;//find
		*filterFlag = mac_br_port_filter_pre_old->appleTalkFilter;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]:MAC_FILTER_AARP\n",__FUNCTION__,__LINE__);
		goto end;
	}

	//MAC_FILTER_MANAGE_INFO://01:80:c2:00:00:00~ 01:80:c2:00:00:ff
	macStart[0] = 0x01;
	macStart[1] = 0x80;
	macStart[2] = 0xc2;
	macStart[3] = 0x0;
	macStart[4] = 0x0;
	if(memcmp(macStart, mac, 5) == 0){
		*find = OMCI_FIND_RULE;//find
		*filterFlag = mac_br_port_filter_pre_old->brMngInfoFilter;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]:MAC_FILTER_MANAGE_INFO\n",__FUNCTION__,__LINE__);
		goto end;
	}
end:
	return ret;
}


int getBPBTDBridgeTableValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	char buffer[120] = {0};//a row string from file
	char *bufferPtr = buffer;	
	char *tableBuffer = NULL;
	char *tempPtr = NULL;
	char tempStr[MAX_MAC_BRIDGE_RECORD_BUF] = {0};
	char macStr[MAX_MAC_BRIDGE_RECORD_BUF] = {0}; //get mac string from row string
	uint8_t mac[OMCI_MAC_LENGTH] = {0};
//	int i = 0;
	uint16_t ageTime = 0;
	/*recordHeadInfo for 9.3.8
	   Bit 	name			settng
	   1		filter/forward		0:forward,1:filter
	   2		reserved			0
	   3		dynamic/static	0:this entry is statically assigned, 1:this entry is dynamically learned
	   4		reserved 			0
	   16..5	age				age in seconds(1..4095)
	*/
	uint16_t recordHeadInfo = 0;
	FILE *fp = NULL;
	int tableSize = 0; //return table size
	uint32_t length = 0;
	uint16_t instanceId = 0;//instance id
	char ifcName[MAX_OMCI_IFC_NAME_LEN] = {0};
	uint8_t findFlag = OMCI_NO_FIND_RULE;
	uint8_t filterFlag = OMCI_MAC_FILTER_FLAG_0; //0:forward, 1:filter
	int ret = 0;
	uint32_t fromLen = 0;
	omci_mac_br_port_br_tbl_ptr mac_br_port_tbl_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	mac_br_port_tbl_attr = (omci_mac_br_port_br_tbl_ptr)me_info->attributes;
    if(mac_br_port_tbl_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

	/*get instance id*/
	instanceId = me_info->inst_id;

 	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]->instanceId = 0x%0x\n",__FUNCTION__,__LINE__,instanceId);


	/*get interface name*/
	ret = getMacBridgePortIfcByInst(instanceId, ifcName);
	if(ret != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]->getMacBridgePortIfcByInst, fail\n",__FUNCTION__,__LINE__);
        goto end;
	}
	
	/*write bridge table infomation to file*/
	memset(buffer, 0, sizeof(buffer));
	sprintf(buffer, "%s showportmacs br0 > /tmp/brctlshowportmacs.txt",OMCI_BRCTL_CMD);
	system(buffer);

	fp = fopen("/tmp/brctlshowportmacs.txt", "r");
	if(fp == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]->fp open is failure\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
	}
	
	/*1.calculate the table size*/
	fseek(fp, 0, SEEK_END);
	tableSize = ftell(fp);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]->tableSize = %d\n",__FUNCTION__,__LINE__, tableSize);

	if(mac_br_port_tbl_attr->brTable.len < tableSize || tableSize < 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]->attribute table size is not enough, failure\n",__FUNCTION__,__LINE__);
		fclose(fp);
        ret = -1;
        goto end;
	}
	
	/*2.malloc memory for table*/
	tableBuffer = mac_br_port_tbl_attr->brTable.buf;
	if(tableBuffer == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s [%d]->attribute table buf is NULL, failure\n",__FUNCTION__,__LINE__);
		fclose(fp);
        ret = -1;
        goto end;
	}
	
	/*3. get mac table information in this port*/
	memset(buffer, 0, sizeof(buffer));
	memset(tempStr, 0, sizeof(tempStr));
	memset(tableBuffer, 0, mac_br_port_tbl_attr->brTable.len);	

	fseek(fp, 0, SEEK_SET);
	fgets(buffer, sizeof(buffer), fp);//jump title row
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]->buffer1=%s\n",__FUNCTION__,__LINE__,buffer);

	length = 0;//reset length to 0 , in order to the table content
	while(fgets(buffer, sizeof(buffer), fp)){
		fromLen = 0;
		/*3.1.get interface from this line*/
		memset(tempStr, 0, sizeof(tempStr));
		ret = findMacBridgeFirstStr(buffer, &fromLen, tempStr);//tempStr include port id and interface name , eg:1(nas0)
		if(ret != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]->findMacBridgeFirstStr fail 1\n",__FUNCTION__,__LINE__);
			continue;
		}

		if(strcmp(tempStr, ifcName) != 0 && strcmp("VEIP", ifcName) != 0){
			continue;
		}
		
		/*3.2.get  mac address from this line*/
		memset(macStr, 0, sizeof(macStr));
		ret = findMacBridgeFirstStr(bufferPtr, &fromLen, macStr);			
		if(ret != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]->findMacBridgeFirstStr fail 2\n",__FUNCTION__,__LINE__);
			continue;
		}
				
		/*3.3.get local? from this line*/
		memset(tempStr, 0, sizeof(tempStr));
		ret = findMacBridgeFirstStr(bufferPtr, &fromLen, tempStr);
		if(ret != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]->findMacBridgeFirstStr fail 3\n",__FUNCTION__,__LINE__);
			continue;
		}
		if(strcmp(tempStr,"no") !=0){
			continue;
		}
		/*3.4.get age time string from this line*/
		memset(tempStr, 0, sizeof(tempStr));
		ret = findMacBridgeFirstStr(bufferPtr, &fromLen, tempStr);
		if(ret != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]->findMacBridgeFirstStr fail 4\n",__FUNCTION__,__LINE__);
			continue;
		}
		ageTime = atoi(tempStr);
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]->ageTime = 0x%02x\n",__FUNCTION__,__LINE__,ageTime);
		
		/*3.5.strip ":" from macStr, get mac address*/
		ret =  getMacFormMacStr(':', macStr, mac);
		if(ret != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]->findMacBridgeFirstStr fail 5\n",__FUNCTION__,__LINE__);
			continue;
		}
		
		/*3.6.search mac address in mac bridge filter table(9.3.6 and 9.3.7)*/				
		findFlag = OMCI_NO_FIND_RULE;
		filterFlag = OMCI_MAC_FILTER_FLAG_0;
		ret =  getSearchFilterMacFormFilterTbl(instanceId, mac, &findFlag, &filterFlag);
		if(ret != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]->getSearchFilterMacFormFilterTbl fail 6\n",__FUNCTION__,__LINE__);
			continue;
		}

		/*3.7 add a record in table*/
		recordHeadInfo = 0;
		recordHeadInfo = (ageTime<<4);//set age time to record information 				
		recordHeadInfo |= (1<<2);//set dynamic mac type to record information
		if((findFlag == OMCI_FIND_RULE) && (filterFlag == OMCI_MAC_FILTER_FLAG_1)){//set filter type to record information
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]->getSearchFilterMacFormFilterTbl find item\n",__FUNCTION__,__LINE__);
			recordHeadInfo |= (1<<0);
		}else{//forward
			//nothing
		}
		tempPtr = (char *)tableBuffer + length;
		put16((uint8_t *)tempPtr, recordHeadInfo);
		memcpy((tempPtr+2), mac, OMCI_MAC_LENGTH);
		length += MAC_FILTER_RECORD_LENGTH;
	}
	fclose(fp);		
	mac_br_port_tbl_attr->brTable.len = length;
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "%s [%d]->length=%d\n",__FUNCTION__,__LINE__,length);
	ret = 0; 
end:
	return ret;
}

